Almost all solved MCQs for you..

Basic MCQs of JavaScript

Basic MCQs of JavaScript

1: Which of the following methods is used to add an element to the end of an array?

  • a) push()
  • b) pop()
  • c) concat()
  • d) shift()

a) push()

2: Which of the following is used to declare a variable in JavaScript?

  • a) let
  • b) var
  • c) const
  • d) All of the above

d) All of the above

3: What is the correct way to check if a variable x is NOT equal to 5 in JavaScript?

  • a) x =! 5
  • b) x != 5
  • c) x !== 5
  • d) x <> 5

c) x !== 5

4: Which built-in method is used to convert a string to lowercase letters?

  • a) toLowerCase()
  • b) lowerCase()
  • c) convertToLower()
  • d) changeCaseToLower()

a) toLowerCase()

5: The “typeof” operator in JavaScript is used to:

  • a) Check if a variable is of type “undefined”
  • b) Determine the type of a variable
  • c) Convert a value to a string
  • d) Create a new variable

b) Determine …

6: What is the output of the following code?

console.log(2 + “3”);

  • a) 23
  • b) 5
  • c) “23”
  • d) 6

c) “23”

7: Which of the following is NOT a valid way to declare a function in JavaScript?

  • a) function myFunction() {}
  • b) var myFunction = function() {}
  • c) const myFunction = () => {}
  • d) let myFunction() {}

d) let myFunction() {}

8: The output of the following code will be:

console.log(typeof null);

  • a) object
  • b) null
  • c) undefined
  • d) number

a) object

9: The “this” keyword in JavaScript refers to:

  • a) The current function
  • b) The global object
  • c) The object that owns the executing code
  • d) The previous object that called the function

c) The object…

10: What is the result of the following expression?

“5” + 2

  • a) 7
  • b) “7”
  • c) “52”
  • d) 52

c) “52”

Advance MCQs of JavaScript

11: How can you add a comment in JavaScript?

  • a) //This is a comment
  • b) <!–This is a comment–>
  • c) This is a comment
  • d) /This is a comment/

a) //This is a comment

12: Which of the following methods is used to remove the last element from an array in JavaScript?

  • a) pop()
  • b) push()
  • c) shift()
  • d) unshift()

a) pop()

13: The “NaN” value in JavaScript stands for:

  • a) Not a Null
  • b) Not a Number
  • c) No Available Number
  • d) Null and Negative

b) Not a Number

14: What is the correct way to write a conditional statement in JavaScript?

  • a) if (x === 5) { … }
  • b) if x = 5 { … }
  • c) if x == 5 then { … }
  • d) if [x = 5] { … }

a) if (x === 5) { … }

15: Which of the following methods is used to remove the first element from an array in JavaScript?

  • a) pop()
  • b) push()
  • c) shift()
  • d) unshift()

c) shift()

16: What is the result of the following expression?

10 % 3

  • a) 1
  • b) 0
  • c) 3.33
  • d) 10

a) 1

17: Which of the following is NOT a valid JavaScript data type?

  • a) boolean
  • b) string
  • c) number
  • d) character

d) character

18: The “splice()” method in JavaScript is used for:

  • a) Sorting an array
  • b) Adding elements to an array
  • c) Removing elements from an array
  • d) Reversing an array

c) Removing elements…

19: What is the output of the following code?

console.log(2 ** 3);

  • a) 8
  • b) 6
  • c) 23
  • d) 9

a) 8

20: Which of the following is used to declare a constant variable in JavaScript?

  • a) let
  • b) var
  • c) const
  • d) final

c) const

JavaScript Online Quiz with Answers

21: What does the “=== ” operator in JavaScript check for?

  • a) Value equality
  • b) Type equality
  • c) Both value and type equality
  • d) None of the above

c) Both value…

22: The output of the following code is:

console.log(Boolean(“”));

  • a) true
  • b) false
  • c) undefined
  • d) null

b) false

23: Which of the following is used to loop through the elements of an array in JavaScript?

  • a) for loop
  • b) while loop
  • c) do-while loop
  • d) All of the above

d) All of the above

24: The “parseInt()” function in JavaScript is used to:

  • a) Convert a string to an integer
  • b) Convert a number to a string
  • c) Round a number to the nearest integer
  • d) Remove decimals from a number

a) Convert a string …

25: What is the correct way to write a JavaScript array?

  • a) [1, 2, 3, 4]
  • b) (1, 2, 3, 4)
  • c) {1, 2, 3, 4}
  • d) “1, 2, 3, 4”

a) [1, 2, 3, 4]

26: What is the result of the following expression?

“5” == 5

  • a) true
  • b) false
  • c) undefined
  • d) null

a) true

27: Which of the following is NOT a valid JavaScript comparison operator?

  • a) ==
  • b) !=
  • c) <=
  • d) ><

d) ><

28: What is the output of the following JavaScript code?

console.log(Math.floor(4.7));

  • a) 4
  • b) 5
  • c) 4.7
  • d) 5.3

a) 4

29: Which of the following is NOT a JavaScript framework or library?

  • a) React
  • b) Angular
  • c) Vue
  • d) JavaFX

d) JavaFX

30: Which of the following methods is used to convert a string to an array in JavaScript?

  • a) split()
  • b) join()
  • c) slice()
  • d) concat()

a) split()

JavaScript Online Test Preparation

31: What is the output of the following code?

console.log(10 > 9 > 8);

  • a) true
  • b) false
  • c) undefined
  • d) error

b) false

32: The “querySelector()” method in JavaScript is used to:

  • a) Select the first element that matches a specified CSS selector
  • b) Add a new CSS class to an element
  • c) Change the CSS style of an element
  • d) Remove an element from the DOM

Answer: a)

33: What is the output of the following code?

console.log(3 + 2 + “7”);

  • a) 12
  • b) 327
  • c) “57”
  • d) 7

c) “57”

34: Which of the following is used to pause the execution of JavaScript code for a specified amount of time?

  • a) setTimeout()
  • b) setInterval()
  • c) clearTimeout()
  • d) clearInterval()

a) setTimeout()

35: What does the “return” statement do in a JavaScript function?

  • a) Stops the execution of the function and returns a value
  • b) Defines a new variable within the function
  • c) Prints a message to the console
  • d) Loops through an array

a) Stops the execution..

12:44 PM
Tags

Post a Comment

[facebook]

MKRdezign

Contact Form

Name

Email *

Message *

Powered by Blogger.
Javascript DisablePlease Enable Javascript To See All Widget