Essential JavaScript Concepts for Junior Developers — Questions & Answers

Test your understanding of key JavaScript topics with these beginner-friendly questions. This quiz covers core JavaScript interview concepts such as variable scope, hoisting, data types, and basic syntax to help you prepare effectively.

This quiz contains 10 questions. Below is a complete reference of all questions, answer choices, and correct answers. You can use this section to review after taking the interactive quiz above.

  1. Question 1: Variable Scopes

    Which keyword in JavaScript declares a variable that is block-scoped and cannot be reassigned after its initial assignment?

    • const
    • cost
    • var
    • let
    Show correct answer

    Correct answer: const

    Explanation: The correct answer is 'const' because it creates a block-scoped variable that cannot be reassigned after being created. 'let' is also block-scoped but allows reassignment. 'var' is function-scoped and not block-scoped, while 'cost' is a typo and not a valid JavaScript keyword.

  2. Question 2: Variable Re-declaration

    What happens if you redeclare a variable using var within the same function scope?

    • It throws an error
    • It is ignored
    • The variable is overwritten
    • It creates a new scope
    Show correct answer

    Correct answer: The variable is overwritten

    Explanation: 'var' allows variable re-declaration within the same scope, so the previously stored value is overwritten with the new one. It does not throw an error like 'let' and 'const' would. Redeclaring with var does not create a new scope, and the statement is not ignored.

  3. Question 3: Hoisting Basics

    Which of the following JavaScript declarations is hoisted to the top of its scope?

    • let
    • import
    • const
    • var
    Show correct answer

    Correct answer: var

    Explanation: 'var' declarations are hoisted to the top of their functional or global scope in JavaScript. 'let' and 'const' are not hoisted in a usable way; accessing them before declaration results in a ReferenceError. The 'import' statement behaves differently and is not hoisted like 'var'.

  4. Question 4: Function Hoisting

    Which type of function can be called before its declaration due to hoisting?

    • Arrow function
    • Anonymous function
    • Function assigned to let
    • Function declaration
    Show correct answer

    Correct answer: Function declaration

    Explanation: Function declarations are hoisted, so they can be called before their actual declaration in the code. Arrow functions and functions assigned to let or const are not hoisted in the same way. An anonymous function is simply a function without a name and may also be assigned to a variable, but unless it's declared via a function declaration, it won't be hoisted.

  5. Question 5: Block Scope Example

    In the following code, what will be logged? let a = 5; if (true) { let a = 10; } console.log(a);

    • ReferenceError
    • 10
    • 5
    • undefined
    Show correct answer

    Correct answer: 5

    Explanation: The correct answer is 5 because the 'let' inside the block creates a new variable scoped only to that block. The 'a' outside remains unchanged. 10 would have been correct if the inner 'a' overwrote the outer one, which it does not. 'undefined' and 'ReferenceError' are incorrect since the variable 'a' is properly declared and initialized in the outer scope.

  6. Question 6: Data Types

    Which of the following is NOT a primitive data type in JavaScript?

    • Boolean
    • String
    • Number
    • Object
    Show correct answer

    Correct answer: Object

    Explanation: 'Object' is not a primitive data type in JavaScript; it is a complex type that can store collections of data. 'Boolean', 'String', and 'Number' are all considered primitive types. The distractors are commonly confused, but only 'Object' fails the primitive test.

  7. Question 7: Declaring Functions

    How do you correctly write a function declaration in JavaScript?

    • fun myFunc() {}
    • let myFunc: function() {}
    • function myFunc() {}
    • var myFunc = () => {}
    Show correct answer

    Correct answer: function myFunc() {}

    Explanation: The standard syntax for declaring a function in JavaScript is 'function myFunc() {}'. Option two is an arrow function expression, not a function declaration. Option three incorrectly uses TypeScript-style syntax, and option four uses an invalid keyword 'fun'.

  8. Question 8: String Concatenation

    Which operator is used to join two strings together in JavaScript?

    • .
    • -
    • +
    • *
    Show correct answer

    Correct answer: +

    Explanation: The '+' operator is used to concatenate strings in JavaScript. The period ('.') is not used for this purpose, nor are '-' or '*'. Using these other operators would produce errors or unintended results.

  9. Question 9: Falsy Values

    Which value is considered 'falsy' in JavaScript?

    • 0
    • "0"
    • "false"
    • []
  10. Question 10: Strict Equality Check

    Which operator checks both value and type for equality in JavaScript?

    • ==
    • ===
    • !=
    • =!=
    Show correct answer

    Correct answer: ===

    Explanation: The strict equality operator '===' checks both the value and the type of its operands. '==' checks value with type coercion, leading to potentially unexpected results. '!=' and '=!=' are not the strict equality operator; the latter is not a valid operator in JavaScript.