Code Baaj

No 1 Digital Knowledge Website

Most 50 Javascript Objective Q & A?

1. Which type of language is JavaScript?

a) Object-Oriented
b) Object-Based
c) Assembly-language
d) High-level
✔️ Answer: b) Object-Based


2. Inside which HTML element do we put the JavaScript?

a) <js>
b) <scripting>
c) <script>
d) <javascript>
✔️ Answer: c) <script>


3. What is the correct syntax for referring to an external script?

a) <script src="app.js">
b) <script href="app.js">
c) <script ref="app.js">
d) <script link="app.js">
✔️ Answer: a) <script src="app.js">


4. How do you write “Hello World” in an alert box?

a) alertBox("Hello World");
b) msgBox("Hello World");
c) msg("Hello World");
d) alert("Hello World");
✔️ Answer: d) alert("Hello World");


5. JavaScript is a ________ Side Scripting Language.

a) Server
b) Browser
c) Client
d) Both a and c
✔️ Answer: d) Both a and c


6. Which of the following is the correct JavaScript syntax to change the content of the HTML element below?

<p id="demo">This is a demo.</p>
a) document.getElementByName("p").innerHTML = "Hello";
b) document.getElement("p").innerHTML = "Hello";
c) document.getElementById("demo").innerHTML = "Hello";
d) document.getId("demo").innerHTML = "Hello";
✔️ Answer: c) document.getElementById("demo").innerHTML = "Hello";


7. Which event occurs when the user clicks on an HTML element?

a) onmouseover
b) onchange
c) onclick
d) onmouseclick
✔️ Answer: c) onclick


8. How do you declare a JavaScript variable?

a) var name;
b) v name;
c) dim name;
d) string name;
✔️ Answer: a) var name;


9. What will typeof null return?

a) “null”
b) “object”
c) “undefined”
d) “number”
✔️ Answer: b) “object”


10. What does NaN stand for?

a) Not a Name
b) Not a Number
c) Name as Number
d) Null as Number
✔️ Answer: b) Not a Number


11. What is the correct way to write a JavaScript array?

a) var colors = (1:"red", 2:"green", 3:"blue")
b) var colors = "red", "green", "blue"
c) var colors = ["red", "green", "blue"]
d) var colors = 1 = ("red"), 2 = ("green"), 3 = ("blue")
✔️ Answer: c) var colors = ["red", "green", "blue"]


12. Which symbol is used for comments in JavaScript?

a) //
b) <!-- -->
c) **
d) #
✔️ Answer: a) //


13. How do you create a function in JavaScript?

a) function = myFunction()
b) function myFunction()
c) function:myFunction()
d) create myFunction()
✔️ Answer: b) function myFunction()


14. What is the output of console.log(typeof [])?

a) array
b) object
c) list
d) string
✔️ Answer: b) object


15. Which operator is used to assign a value to a variable?

a) =
b) ==
c) :=
d) ===
✔️ Answer: a) =


16. What is the output of console.log(2 + '2')?

a) 4
b) “22”
c) NaN
d) Error
✔️ Answer: b) “22”


17. Which keyword is used to check whether a value is not a number?

a) isNaN()
b) isNan()
c) NaN()
d) nonNumber()
✔️ Answer: a) isNaN()


18. What does the push() method do?

a) Removes last element
b) Adds an element at the end
c) Adds an element at the beginning
d) Sorts the array
✔️ Answer: b) Adds an element at the end


19. Which method converts JSON to a JavaScript object?

a) JSON.convert()
b) JSON.parse()
c) JSON.stringify()
d) JSON.toJS()
✔️ Answer: b) JSON.parse()


20. Which method returns the character at the specified index?

a) charAt()
b) getChar()
c) characterAt()
d) indexChar()
✔️ Answer: a) charAt()


21. Which function of Array joins all elements into a string?

a) join()
b) merge()
c) convert()
d) toString()
✔️ Answer: a) join()


22. What will typeof undefined return?

a) “null”
b) “undefined”
c) “object”
d) “error”
✔️ Answer: b) “undefined”


23. What is the output of 10 + true?

a) 10
b) 11
c) NaN
d) Error
✔️ Answer: b) 11


24. What is === in JavaScript?

a) Assignment
b) Compare values only
c) Strict equality (value + type)
d) Type check only
✔️ Answer: c) Strict equality (value + type)


25. How do you stop a loop in JavaScript?

a) break
b) stop
c) halt
d) exit
✔️ Answer: a) break


26. Which of these is not a JavaScript loop structure?

a) for
b) while
c) foreach
d) loop
✔️ Answer: d) loop


27. Which method removes the last element of an array?

a) pop()
b) push()
c) shift()
d) remove()
✔️ Answer: a) pop()


28. Which statement is used to skip an iteration in a loop?

a) break
b) continue
c) skip
d) pass
✔️ Answer: b) continue


29. What is the default value of uninitialized variable in JavaScript?

a) null
b) undefined
c) 0
d) false
✔️ Answer: b) undefined


30. How can you convert a string to a number in JavaScript?

a) Number()
b) parseInt()
c) parseFloat()
d) All of the above
✔️ Answer: d) All of the above


31. Which object in JavaScript lets you work with dates and times?

a) Date
b) Time
c) Calendar
d) Clock
✔️ Answer: a) Date


32. Which keyword is used to define a constant in JS?

a) constant
b) let
c) const
d) define
✔️ Answer: c) const


33. What is Math.floor(4.7)?

a) 5
b) 4.7
c) 4
d) 0
✔️ Answer: c) 4


34. Which method can be used to find the length of a string?

a) count()
b) length()
c) len
d) .length
✔️ Answer: d) .length


35. Which operator is used to compare both value and type?

a) ==
b) =
c) ===
d) :=
✔️ Answer: c) ===


36. JavaScript is ______ typed.

a) Statically
b) Dynamically
c) Strongly
d) Loosely
✔️ Answer: b) Dynamically


37. What does setTimeout() do?

a) Repeats code forever
b) Executes code once after delay
c) Loops code
d) Stops execution
✔️ Answer: b) Executes code once after delay


38. Which method executes a function once after a specified time?

a) setInterval()
b) setDelay()
c) setTimeout()
d) setPause()
✔️ Answer: c) setTimeout()


39. What is closure in JavaScript?

a) Object inside array
b) Function with private variables
c) Function that stops execution
d) None
✔️ Answer: b) Function with private variables


40. How to write an arrow function?

a) (x) => x * 2
b) ->(x) x * 2
c) (x) => { return x * 2; }
d) Both a and c
✔️ Answer: d) Both a and c


41. isNaN("123") returns:

a) true
b) false
c) NaN
d) Error
✔️ Answer: b) false


42. Which keyword creates a block-scoped variable?

a) var
b) block
c) let
d) scope
✔️ Answer: c) let


43. Which built-in method reverses the order of the elements in an array?

a) changeOrder(order)
b) reverse()
c) order()
d) sort(order)
✔️ Answer: b) reverse()


44. How do you check if x is an array?

a) typeof x === 'array'
b) x.isArray()
c) Array.isArray(x)
d) x instanceof array
✔️ Answer: c) Array.isArray(x)


45. What is a callback function?

a) Function passed into another function
b) Loop function
c) Static function
d) Recursive function
✔️ Answer: a) Function passed into another function


46. What is the scope of a variable declared with let?

a) Global
b) Local
c) Block
d) Function
✔️ Answer: c) Block


47. What is the output of true + false?

a) 1
b) truefalse
c) NaN
d) Error
✔️ Answer: a) 1


48. JavaScript can run outside the browser using?

a) Chrome only
b) Node.js
c) React.js
d) Angular
✔️ Answer: b) Node.js


49. What will console.log(typeof NaN) output?

a) number
b) NaN
c) undefined
d) object
✔️ Answer: a) number


50. What does the shift() method do in an array?

a) Adds to the end
b) Removes the last item
c) Removes the first item
d) Adds to the front
✔️ Answer: c) Removes the first item


Leave a Reply

Your email address will not be published. Required fields are marked *