JavaScript Basics Quiz: Core Concepts for Frontend Development Quiz

Challenge your understanding of fundamental JavaScript concepts with these questions designed for those starting their journey in frontend development. Explore essential topics such as variable declarations, data types, operators, and simple control structures to solidify your programming foundation.

  1. Variable Declaration Syntax

    Which keyword is used in JavaScript to declare a variable that can be updated later, as shown in let score = 10?

    1. let
    2. varr
    3. constt
    4. declar

    Explanation: The correct keyword is 'let', which allows variables to be updated after declaration. 'varr' and 'constt' are incorrect as they're misspellings of actual keywords. 'const' is valid in JavaScript but creates variables that cannot be reassigned, while 'declar' is not a JavaScript keyword.

  2. String Concatenation

    What will be the value of result after executing result = 'Hello' + ' ' + 'World' in JavaScript?

    1. Hello World
    2. HelloWorld
    3. Hello+World
    4. Hello,World

    Explanation: The plus (+) operator concatenates strings in JavaScript, so 'Hello' + ' ' + 'World' produces 'Hello World' with a space. 'HelloWorld' omits the space, which the expression does not do. 'Hello+World' would occur only if plus signs were within the strings. 'Hello,World' is incorrect as there are no commas in the concatenation.

  3. Data Types

    If you declare let isActive = true; in JavaScript, what is the data type of isActive?

    1. boolean
    2. string
    3. number
    4. null

    Explanation: 'boolean' is correct because true and false are Boolean values. 'string' refers to text data, for example 'true' (with quotes). 'number' is for numeric values, not suitable for true. 'null' stands for the absence of any object value, which is different from true or false.

  4. Arithmetic Operators

    Which symbol is used to multiply two numbers in JavaScript, as in result = 3 * 4?

    1. *
    2. %
    3. ^
    4. #

    Explanation: The asterisk (*) is the multiplication operator in JavaScript. The percent sign (%) is used for the modulo operation, not multiplication. The caret (^) is for bitwise XOR, not multiplication, and the hash symbol (#) is not used as an arithmetic operator in JavaScript.

  5. Strict Equality Comparison

    What does the === operator check for in JavaScript?

    1. Both value and type equality
    2. Only value equality
    3. Only type equality
    4. Assignment

    Explanation: The '===' operator checks if the compared values are equal in both value and type. Using '==' checks only value equality, which may perform type conversion. 'Only type equality' is incorrect, as the operator checks more than just type. 'Assignment' is handled by the '=' operator, not '==='.

  6. Function Declaration

    Which line correctly declares a basic function named greet in JavaScript?

    1. function greet() {}
    2. declare greet() {}
    3. func greet() {}
    4. create function greet[] {}

    Explanation: The correct syntax to declare a function is 'function greet() {}'. 'declare greet() {}' is not valid JavaScript syntax. 'func' is not a JavaScript keyword, and 'create function greet[] {}' wrongly uses square brackets and extra text.

  7. Array Indexing

    Given let colors = ['red', 'green', 'blue'], what is the value of colors[1]?

    1. green
    2. red
    3. blue
    4. yellow

    Explanation: Arrays in JavaScript are zero-indexed, so colors[0] is 'red', and colors[1] is 'green'. 'blue' is at index 2, while 'yellow' isn’t in the array. 'red' is the first element, but the question asks for the second.

  8. If Statement Usage

    What is the correct way to write a simple if statement to check if age is greater than 18 in JavaScript?

    1. if (age > 18) {}
    2. if age > 18 then {}
    3. if [age > 18] {}
    4. if (age => 18) {}

    Explanation: The 'if (age > 18) {}' syntax is the correct way in JavaScript. 'if age > 18 then {}' is not JavaScript syntax but resembles other programming languages. 'if [age > 18] {}' incorrectly uses square brackets, and 'if (age => 18) {}' incorrectly uses the assignment arrow instead of the greater-than operator.

  9. Comment Syntax

    Which of the following is the correct single-line comment in JavaScript?

    1. // This is a comment
    2. # This is a comment
    3. <!-- This is a comment -->
    4. -- This is a comment

    Explanation: JavaScript uses double slashes (//) for single-line comments. The hash (#) denotes comments in some other languages but not in JavaScript. '<!-- ... -->' is for HTML comments. Double dash (--) is not comment syntax in JavaScript.

  10. Undefined Value

    If you declare let value; without assigning anything, what is the value of value?

    1. undefined
    2. null
    3. empty
    4. zero

    Explanation: A variable declared without assignment automatically gets the value 'undefined' in JavaScript. 'null' is a specific assigned value indicating no value, not the default. 'empty' is not a data type or value in JavaScript, and 'zero' (0) is a numeric value, not the default for uninitialized variables.