Any2Quiz
Computer Science / Languages / JavaScript

Syntax Quiz - Languages JavaScript

Free practice quiz: Syntax (Languages JavaScript). 54 multiple-choice questions with answers and explanations. Play online, no sign-up needed.

Play all 54 questions free

Sample questions

  1. Which keyword is used to declare a variable in JavaScript that cannot be reassigned?

    1. var
    2. let
    3. const
    4. static
    Show answer

    Answer: C. const

    The `const` keyword declares a block-scoped variable whose value cannot be reassigned after its initial declaration. `var` and `let` allow reassignment.

  2. Which syntax is used to access the first element of an array named `myArray` in JavaScript?

    1. myArray(0)
    2. myArray[0]
    3. myArray{0}
    4. myArray.0
    Show answer

    Answer: B. myArray[0]

    Array elements in JavaScript are accessed using zero-based indexing within square brackets `[]`.

  3. What is the result of `3 + '3'` in JavaScript?

    1. 6
    2. '6'
    3. NaN
    4. Error
    Show answer

    Answer: B. '6'

    JavaScript performs type coercion. When a number is added to a string, the number is converted to a string, and then string concatenation occurs.

  4. How do you create a multi-line string in JavaScript without using template literals?

    1. Using backticks (` `` `)
    2. Using a backslash `\` at the end of each line
    3. Using a plus sign `+` to concatenate strings on separate lines
    4. Using single quotes `'` on each line
    Show answer

    Answer: B. Using a backslash `\` at the end of each line

    To create multi-line strings without template literals, you can use the backslash `\` at the end of a line to indicate continuation, or concatenate strings using `+` on subsequent lines.

  5. What is the purpose of the `debugger` statement in JavaScript?

    1. To end program execution
    2. To create a new variable
    3. To pause JavaScript execution and trigger a debugger tool
    4. To define a function
    Show answer

    Answer: C. To pause JavaScript execution and trigger a debugger tool

    The `debugger` statement can be used to pause the execution of JavaScript code, allowing developers to inspect variables and step through the code using a debugger.

Take the full quiz

More quizzes

Browse all JavaScript quizzes