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 freeSample questions
Which keyword is used to declare a variable in JavaScript that cannot be reassigned?
- var
- let
- const
- 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.
Which syntax is used to access the first element of an array named `myArray` in JavaScript?
- myArray(0)
- myArray[0]
- myArray{0}
- myArray.0
Show answer
Answer: B. myArray[0]
Array elements in JavaScript are accessed using zero-based indexing within square brackets `[]`.
What is the result of `3 + '3'` in JavaScript?
- 6
- '6'
- NaN
- 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.
How do you create a multi-line string in JavaScript without using template literals?
- Using backticks (` `` `)
- Using a backslash `\` at the end of each line
- Using a plus sign `+` to concatenate strings on separate lines
- 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.
What is the purpose of the `debugger` statement in JavaScript?
- To end program execution
- To create a new variable
- To pause JavaScript execution and trigger a debugger tool
- 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.