MCQ Related “JavaScript”

  1. What does JS stand for?
    • A) Java System
    • B) JavaScript
    • C) Jumping Script
    • D) None of the above
  2. Which of the following is a JavaScript data type?
    • A) Number
    • B) String
    • C) Boolean
    • D) All of the above
  3. Where is client-side JavaScript executed?
    • A) Server
    • B) Client’s browser
    • C) Cloud
    • D) Mainframe
  4. Which of the following is the correct syntax to declare a variable in JavaScript?
    • A) var variableName;
    • B) variable variableName;
    • C) v variableName;
    • D) declare variableName;
  5. What symbol is used for comments in JavaScript?
    • A) //
    • B) **
    • C) ##
    • D) !!
  6. How do you create a function in JavaScript?
    • A) function = myFunction()
    • B) function myFunction()
    • C) function:myFunction()
    • D) myFunction = function()
  7. Which of the following is not a reserved keyword in JavaScript?
    • A) function
    • B) let
    • C) var
    • D) objectify
  8. How to write an if statement in JavaScript?
    • A) if i = 5 then
    • B) if (i == 5)
    • C) if i == 5
    • D) if i = 5
  9. What is the output of the following code: console.log(typeof(null));?
    • A) “null”
    • B) “object”
    • C) “undefined”
    • D) “number”
  10. Which method is used to round a number in JavaScript?
    • A) Math.ceil()
    • B) Math.round()
    • C) Math.floor()
    • D) Math.random()
  11. What will be the result of "5" + 3 in JavaScript?
    • A) 8
    • B) “53”
    • C) 53
    • D) “8”
  12. How do you add a comment in JavaScript?
    • A) /* comment */
    • B) // comment
    • C) # comment
    • D) Both A and B
  13. Which of the following methods can be used to add an element to the end of an array?
    • A) push()
    • B) add()
    • C) append()
    • D) insert()
  14. What does NaN stand for in JavaScript?
    • A) Not a Number
    • B) Negative a Number
    • C) Null a Number
    • D) None of the above
  15. What keyword is used to define a constant in JavaScript?
    • A) constant
    • B) const
    • C) finalize
    • D) let
  16. Which operator is used to assign a value to a variable in JavaScript?
    • A) –
    • B) =
    • C) ==
    • D) ==
  17. How can you convert a string to a number in JavaScript?
    • A) parseInt()
    • B) Number()
    • C) Both A and B
    • D) ToString()
  18. Which of the following is the correct way to write an array in JavaScript?
    • A) var arr = (1, 2, 3)
    • B) var arr = [1, 2, 3]
    • C) var arr = {1, 2, 3}
    • D) var arr = <1, 2, 3>
  19. How do you define an object in JavaScript?
    • A) var obj = {}
    • B) var obj = []
    • C) var obj = ()
    • D) var obj = <>
  20. What is the output of console.log(2 + '2');?
    • A) 4
    • B) 22
    • C) “4”
    • D) “22”
  21. What will be the output of typeof([]);?
    • A) “array”
    • B) “object”
    • C) “list”
    • D) “undefined”
  22. In JavaScript, which symbol is used for logical AND?
    • A) &&
    • B) ||
    • C) &
    • D) !
  23. What is the output of console.log(1 == '1');?
    • A) true
    • B) false
    • C) undefined
    • D) NaN
  24. Which method is used to remove the last element from an array?
    • A) pop()
    • B) shift()
    • C) slice()
    • D) delete()
  25. What is the purpose of the this keyword in JavaScript?
    • A) Refers to the current function
    • B) Refers to the current object
    • C) Refers to the parent object
    • D) None of the above
  26. What does the Array.isArray() method do?
    • A) Checks if the value is an array
    • B) Creates a new array
    • C) Converts an array to a string
    • D) None of the above
  27. Which of the following is not a looping structure in JavaScript?
    • A) for
    • B) while
    • C) do-while
    • D) until
  28. How do you access the first element of an array named myArray?
    • A) myArray[0]
    • B) myArray(1)
    • C) myArray{1}
    • D) myArray.first()
  29. What keyword is used to create a new object in JavaScript?
    • A) new
    • B) create
    • C) class
    • D) object
  30. Which built-in method combines two or more arrays?
    • A) combine()
    • B) concat()
    • C) merge()
    • D) join()
  31. Which of the following functions can be used to display data in an alert box?
    • A) window.alert()
    • B) alert()
    • C) Both A and B
    • D) Show.alert()
  32. What is the purpose of the return statement in a function?
    • A) To end the function
    • B) To return a value
    • C) Both A and B
    • D) To pause the function
  33. How do you check for an undefined variable in JavaScript?
    • A) if(variable === null)
    • B) if(variable === undefined)
    • C) if(variable == undefined)
    • D) All of the above
  34. Which of the following will cause an error in JavaScript?
    • A) var a = 1;
    • B) var a = “Hello”;
    • C) var a = undefined;
    • D) var a = NaN;
  35. How do you create a new empty object in JavaScript?
    • A) var obj = {};
    • B) var obj = [];
    • C) var obj = new Object();
    • D) Both A and C
  36. How do you define a named function in JavaScript?
    • A) function myFunction() { }
    • B) function = myFunction() { }
    • C) myFunction() { }
    • D) function:myFunction() { }
  37. What will console.log(0.1 + 0.2 === 0.3); output in JavaScript?
    • A) true
    • B) false
    • C) undefined
    • D) NaN
  38. Which of the following is not a valid variable name in JavaScript?
    • A) myVar
    • B) $myVar
    • C) my-var
    • D) _myVar
  39. How do you define an arrow function in JavaScript?
    • A) const myFunction = () => { }
    • B) const myFunction = function() { }
    • C) myFunction() => { }
    • D) function => myFunction() { }
  40. In JavaScript, which symbol is used for logical OR?
    • A) |
    • B) ||
    • C) &
    • D) AND
  41. How can you create an instance of an object in JavaScript?
    • A) Using the new keyword
    • B) Simply declaring it
    • C) Using the create method
    • D) None of the above
  42. What is the output of console.log(1 < 2 < 3);?
    • A) true
    • B) false
    • C) NaN
    • D) undefined
  43. Which of the following is a way to iterate over an array?
    • A) forEach()
    • B) map()
    • C) filter()
    • D) All of the above
  44. Which function is used to parse a string to an integer in JavaScript?
    • A) parseFloat()
    • B) toNumber()
    • C) parseInt()
    • D) convert()
  45. How do you prevent a default action in an event handler?
    • A) event.preventDefault()
    • B) return false
    • C) Both A and B
    • D) stopPropagation()
  46. What is a closure in JavaScript?
    • A) A scope that contains variables
    • B) A defined function inside another function
    • C) Both A and B
    • D) A way to close an application
  47. What will null == undefined return in JavaScript?
    • A) true
    • B) false
    • C) undefined
    • D) NaN
  48. In which situation would you use the JSON.parse() method?
    • A) To convert an object to a string
    • B) To convert a string to an object
    • C) To parse JSON data from an API
    • D) Both B and C
  49. Which of the following can throw an error in JavaScript?
    • A) Syntax error
    • B) Reference error
    • C) Type error
    • D) All of the above
  50. What does the map() method return?
    • A) A new array with the results of calling a function for every array element
    • B) A single value
    • C) The original array
    • D) An object