JavaScript Logic Mastery Quiz Quiz

  1. Variable Scope in Functions

    What will be the output of the following code: var a = 5; function test() { var a = 10; console.log(a); } test();

    1. 10
    2. 5
    3. undefined
    4. ReferenceError
    5. 'a'
  2. Understanding typeof Operator

    What is the result of typeof null in JavaScript?

    1. 'object'
    2. 'null'
    3. 'undefined'
    4. 'Null'
    5. 'none'
  3. Implicit Type Coercion

    What is the output of this expression: '2' + 2 + 2?

    1. '222'
    2. 6
    3. '24'
    4. '22'
    5. NaN
  4. Closures in JavaScript

    Which of the following best describes a closure in JavaScript?

    1. A function with access to its own scope, the outer function's scope, and the global scope
    2. A variable that stores a list of functions
    3. A method to create private variables only in classes
    4. An array that stores other arrays
    5. A function that is immediately invoked after definition
  5. Array Methods

    Given: var arr = [1, 2, 3]; After arr.push(4), what is arr?

    1. [1, 2, 3, 4]
    2. [4, 1, 2, 3]
    3. [1, 2, 3, 4, undefined]
    4. [1, 2, 3]
    5. [1, 4, 2, 3]
  6. Equality Comparison

    What is the result of this JavaScript expression: 0 == '0'?

    1. true
    2. false
    3. undefined
    4. null
    5. '0'
  7. Arrow Functions Syntax

    Which option correctly creates an arrow function that doubles a number?

    1. x =u003E x * 2
    2. (x) =u003E x * 2
    3. function(x) =u003E { x * 2 }
    4. x -u003E x * 2
    5. double(x) x * 2
  8. Primitive vs Reference Types

    What happens when you compare two distinct arrays with the same elements using ===?

    1. false
    2. true
    3. undefined
    4. Throws an error
    5. 'arrays are same'
  9. Hoisting Behavior

    What will be logged: console.log(b); var b = 4;

    1. undefined
    2. 4
    3. ReferenceError
    4. null
    5. 'b'
  10. ParseInt Function Quirks

    What is the result of parseInt('08') in JavaScript?

    1. 8
    2. 0
    3. NaN
    4. undefined
    5. '8'