All featured quizzes

JavaScript - Basics

Array methods, object property access, type coercion, and NaN checking.

Sample Questions

A preview of what's in this quiz. Answer them interactively for instant scoring and full explanations.

Which keyword is used to declare a block-scoped variable that can be reassigned?

1. Which keyword is used to declare a block-scoped variable that can be reassigned?

  • A.var
  • B.const
  • C.let
  • D.define
Which keyword is used to declare a block-scoped variable that cannot be reassigned (read-only)?

2. Which keyword is used to declare a block-scoped variable that cannot be reassigned (read-only)?

  • A.let
  • B.var
  • C.const
  • D.immutable
Which logical operator represents logical NOT?

3. Which logical operator represents logical NOT?

  • A.not
  • B.&&
  • C.!
  • D.||
Which logical operator represents logical OR?

4. Which logical operator represents logical OR?

  • A.&&
  • B.!
  • C.||
  • D.|
Which operator is the modulus operator used to get the remainder of a division?

5. Which operator is the modulus operator used to get the remainder of a division?

  • A./
  • B.mod
  • C.%
  • D.div
What is the return type of the expression `typeof NaN`?

6. What is the return type of the expression `typeof NaN`?

  • A.NaN
  • B.undefined
  • C.number
  • D.object
Which operator is the strict equality operator that compares both value and type?

7. Which operator is the strict equality operator that compares both value and type?

  • A.==
  • B.=
  • C.===
  • D.equal
What does the `typeof` operator return for `null` in JavaScript?

8. What does the `typeof` operator return for `null` in JavaScript?

  • A.null
  • B.undefined
  • C.object
  • D.value
What does `NaN` stand for in JavaScript?

9. What does `NaN` stand for in JavaScript?

  • A.Null and Nullify
  • B.New Array Number
  • C.Not-a-Number
  • D.Negative Auxiliary Number
What does the `typeof` operator return for an undefined variable?

10. What does the `typeof` operator return for an undefined variable?

  • A.null
  • B.object
  • C.undefined
  • D.error
What is the scope of a variable declared with the `var` keyword?

11. What is the scope of a variable declared with the `var` keyword?

  • A.Block scope
  • B.Local scope only to curly braces
  • C.Function scope
  • D.No scope restrictions
What is the difference between `==` and `===` operators?

12. What is the difference between `==` and `===` operators?

  • A.=== performs type coercion; == does not.
  • B.== is for strings; === is for numbers.
  • C.== performs type coercion; === does not.
  • D.There is no difference; they are identical.
Which logical operator represents logical AND?

13. Which logical operator represents logical AND?

  • A.||
  • B.!
  • C.&&
  • D.&
How do you write a single-line comment in JavaScript?

14. How do you write a single-line comment in JavaScript?

  • A./* this is a comment */
  • B.# this is a comment
  • C.// this is a comment
  • D.<!-- this is a comment -->
Which built-in function displays a dialog box with a message and an OK button to alert users?

15. Which built-in function displays a dialog box with a message and an OK button to alert users?

  • A.console.log()
  • B.prompt()
  • C.alert()
  • D.confirm()
Which built-in method writes messages to the developer console for debugging?

16. Which built-in method writes messages to the developer console for debugging?

  • A.print()
  • B.document.write()
  • C.console.log()
  • D.alert()
Which built-in function prompts the user to enter text input in a dialog box?

17. Which built-in function prompts the user to enter text input in a dialog box?

  • A.alert()
  • B.confirm()
  • C.prompt()
  • D.input()
How do you write a multi-line comment in JavaScript?

18. How do you write a multi-line comment in JavaScript?

  • A.// this is a comment
  • B.<!-- this is a comment -->
  • C./* this is a comment */
  • D.## this is a comment ##
How do you create a basic empty object in JavaScript?

19. How do you create a basic empty object in JavaScript?

  • A.let person = [];
  • B.let person = ();
  • C.let person = {};
  • D.let person = Object.empty();
What index represents the first element in a JavaScript array?

20. What index represents the first element in a JavaScript array?

  • A.1
  • B.-1
  • C.0
  • D.0.1

Looking for a different topic? Browse all subjects