MCQs on Basics of Syntax and Language | JavaScript

Understanding syntax and language fundamentals is crucial for mastering code structure and flow. This guide focuses on core concepts like variables, data types, operators, and comments, laying the groundwork for dynamic programming.


Multiple Choice Questions

Variables (let, const, var)

  1. Which keyword is used to declare a variable that can be reassigned?
    • A) const
    • B) var
    • C) let
    • D) both B and C
  2. What is the main difference between let and const?
    • A) let allows reassignment, while const does not.
    • B) const allows reassignment, while let does not.
    • C) Both cannot be reassigned.
    • D) const can only be used in functions.
  3. If you declare a variable with var, where is it accessible?
    • A) Only within the function scope
    • B) Only in the block it is defined
    • C) Globally, if declared outside a function
    • D) Only inside a loop
  4. Which variable declaration keyword introduces block-level scoping?
    • A) var
    • B) let
    • C) const
    • D) both B and C
  5. What happens if you try to reassign a const variable?
    • A) It reassigns successfully.
    • B) An error is thrown.
    • C) The variable resets to null.
    • D) It gets reassigned without errors.

Data Types (String, Number, Boolean, Null, Undefined, Symbol)

  1. Which data type is used to represent text?
    • A) String
    • B) Boolean
    • C) Number
    • D) Symbol
  2. What will be the result of typeof undefined?
    • A) null
    • B) object
    • C) undefined
    • D) boolean
  3. Which of the following represents a Boolean value?
    • A) “true”
    • B) 1
    • C) true
    • D) “false”
  4. Which data type would NaN belong to?
    • A) Boolean
    • B) String
    • C) Number
    • D) Undefined
  5. Which of the following statements is true?
    • A) Symbols are used to create unique identifiers.
    • B) Numbers include both integer and string types.
    • C) Undefined and null are of the same data type.
    • D) A String can be only a single character.
  6. What does typeof null return in JavaScript?
    • A) undefined
    • B) null
    • C) object
    • D) string
  7. Which data type is primarily used to represent a true or false condition?
    • A) Boolean
    • B) String
    • C) Number
    • D) Undefined

Operators (Arithmetic, Assignment, Comparison, Logical)

  1. What will be the result of 5 + 3 * 2?
    • A) 16
    • B) 11
    • C) 10
    • D) 13
  2. Which operator assigns a value to a variable?
    • A) ==
    • B) *
    • C) =
    • D) ===
  3. What does the === operator check for in JavaScript?
    • A) Value equality only
    • B) Type equality only
    • C) Both value and type equality
    • D) Inequality
  4. Which of the following is a logical operator?
    • A) &&
    • B) ==
    • C) ?
    • D) %
  5. What will 10 % 3 return?
    • A) 0
    • B) 1
    • C) 2
    • D) 3
  6. What does ++ do in JavaScript?
    • A) Increments a value by 1
    • B) Adds 2 to a value
    • C) Multiplies a value by 2
    • D) Returns a boolean
  7. Which symbol represents the “not equal” operator in JavaScript?
    • A) ==
    • B) !==
    • C) <>
    • D) ===
  8. Which operator is used to concatenate two strings in JavaScript?
    • A) +
    • B) –
    • C) *
    • D) %
  9. What will be the result of true && false?
    • A) true
    • B) false
    • C) undefined
    • D) NaN
  10. Which comparison operator checks for loose equality in JavaScript?
    • A) ==
    • B) ===
    • C) <=
    • D) >=

Comments in JavaScript

  1. How do you write a single-line comment in JavaScript?
    • A) //
    • B) <!– –>
    • C) /*
    • D) **
  2. Which symbol pair is used for multi-line comments?
    • A) //
    • B) <!– –>
    • C) /*
    • D) **
  3. Why are comments important in JavaScript code?
    • A) They improve code readability.
    • B) They are used for error checking.
    • C) They add to program speed.
    • D) They make the code shorter.
  4. Which of the following is not a type of comment in JavaScript?
    • A) Inline comment
    • B) Block comment
    • C) Document comment
    • D) Nested comment
  5. What is a common use of comments in code?
    • A) To add explanatory notes
    • B) To delete code
    • C) To make the code run faster
    • D) To execute debugging commands
  6. Can you nest multi-line comments in JavaScript?
    • A) Yes
    • B) No
    • C) Only in certain browsers
    • D) Only with strict mode
  7. Which of the following would cause an error?
    • A) Nested multi-line comments
    • B) Nested single-line comments
    • C) A single-line comment within a block comment
    • D) Using a multi-line comment on a single line
  8. Where should comments ideally be placed for best readability?
    • A) At the end of each line of code
    • B) Only at the top of the file
    • C) Close to the related code
    • D) Separate comment file

Answer Key

QnoAnswer
1D) both B and C
2A) let allows reassignment, while const does not.
3C) Globally, if declared outside a function
4D) both B and C
5B) An error is thrown
6A) String
7C) undefined
8C) true
9C) Number
10A) Symbols are used to create unique identifiers.
11C) object
12A) Boolean
13B) 11
14C) =
15C) Both value and type equality
16A) &&
17B) 1
18A) Increments a value by 1
19B) !==
20A) +
21B) false
22A) ==
23A) //
24C) /*
25A) They improve code readability.
26D) Nested comment
27A) To add explanatory notes
28B) No
29A) Nested multi-line comments
30C) Close to the related code

Use a Blank Sheet, Note your Answers and Finally tally with our answer at last. Give Yourself Score.

X
error: Content is protected !!
Scroll to Top