JavaScript Multiple Choice Question

Question : 1 What is the result of the following expression: 5 + "3"?

  • A

    8

  • B

    53

  • C

    35

  • D

    NaN

Answer:

Question : 2 Which of the following is NOT a valid way to declare a variable in JavaScript?

  • A

    var x = 5;

  • B

    let y = 3;

  • C

    const z = 10;

  • D

    variable w = 8;

Answer:

Question : 3 What is the result of the following expression: "20" - 5?

  • A

    15

  • B

    25

  • C

    20

  • D

    NaN

Answer:

Question : 4 Which keyword is used to define a function in JavaScript?

  • A

    function

  • B

    define

  • C

    func

  • D

    funciton

Answer:

Question : 5 What is the result of the following expression: typeof 42?

  • A

    number

  • B

    string

  • C

    undefined

  • D

    object

Answer:

Question : 6 What does the "===" operator do in JavaScript?

  • A

    Checks for equality without type conversion

  • B

    Checks for equality with type conversion

  • C

    Assigns a value to a variable

  • D

    Compares two variables

Answer:

Question : 7 What is the output of the following code snippet? ```javascript console.log(1 + "2" + "2"); ```

  • A

    122

  • B

    32

  • C

    1222

  • D

    5

Answer:

Question : 8 What is the correct way to write a comment in JavaScript?

  • A

    //This is a comment

  • B

    <!--This is a comment-->

  • C

    #This is a comment

  • D

    /* This is a comment */

Answer:

Question : 9 Which built-in method adds one or more elements to the end of an array and returns the new length of the array?

  • A

    push()

  • B

    add()

  • C

    concat()

  • D

    append()

Answer:

Question : 10 Which of the following is NOT a valid data type in JavaScript?

  • A

    number

  • B

    boolean

  • C

    character

  • D

    string

Answer:

Question : 11 Which of the following is the correct way to declare a JavaScript array?

  • A

    var colors = {};

  • B

    var colors = [];

  • C

    var colors = ();

  • D

    var colors = "";

Answer:

Question : 12 What does the "&&" operator do in JavaScript?

  • A

    Logical OR

  • B

    Logical AND

  • C

    Bitwise OR

  • D

    Bitwise AND

Answer:

Question : 13 What is the result of the following expression: 5 * "3"?

  • A

    15

  • B

    53

  • C

    35

  • D

    NaN

Answer:

Question : 14 Which method is used to remove the last element from an array in JavaScript?

  • A

    pop()

  • B

    remove()

  • C

    delete()

  • D

    splice()

Answer:

Question : 15 What is the output of the following code snippet? ```javascript console.log("5" + 3); ```

  • A

    53

  • B

    8

  • C

    15

  • D

    NaN

Answer:

Question : 16 Which of the following is NOT a valid JavaScript variable name?

  • A

    myVar

  • B

    3var

  • C

    _var

  • D

    $var

Answer:

Question : 17 What is the correct way to round the number 7.25 to the nearest integer in JavaScript?

  • A

    Math.round(7.25)

  • B

    round(7.25)

  • C

    Math.ceil(7.25)

  • D

    Math.floor(7.25)

Answer:

Question : 18 What does the "||" operator do in JavaScript?

  • A

    Logical AND

  • B

    Bitwise OR

  • C

    Logical OR

  • D

    Bitwise AND

Answer:

Question : 19 What is the result of the following expression: "Hello".length?

  • A

    Hello

  • B

    5

  • C

    undefined

  • D

    NaN

Answer:

Question : 20 Which built-in method returns the index of the first occurrence of a specified value in a string?

  • A

    indexOf()

  • B

    search()

  • C

    find()

  • D

    locate()

Answer: