πŸ“Š JavaScript
Q. The type of a variable that is volatile is
  • (A) Volatile variable
  • (B) Mutable variable
  • (C) Immutable variable
  • (D) Dynamic variable
πŸ’¬ Discuss
βœ… Correct Answer: (B) Mutable variable

Explanation:

A volatile variable refers to a variable whose value can change unexpectedly due to external factors such as hardware changes, multi-threading, or signal handlers. Such variables are typically mutable, meaning they can be modified during program execution.

Other options:

  • (A) Volatile variable β†’ While "volatile" is a keyword in some languages like C and Java, it does not define a variable type; rather, it is a qualifier.
  • (C) Immutable variable β†’ Incorrect, as immutable variables cannot change once assigned.
  • (D) Dynamic variable β†’ This usually refers to variables that are allocated dynamically in memory but does not specifically relate to volatility.

Thus, the correct answer is (B) Mutable variable.

πŸ“Š JavaScript
Q. A hexadecimal literal begins with
  • (A) 00
  • (B) 0x
  • (C) 0X
  • (D) Both 0x and 0X
πŸ’¬ Discuss
βœ… Correct Answer: (D) Both 0x and 0X

Explanation:

The correct answer is:

(D) Both 0x and 0X

Explanation:

In most programming languages (such as C, C++, Java, JavaScript, and Python), a hexadecimal literal starts with either 0x or 0X. Both notations are valid and indicate that the number is in hexadecimal (base 16) format.

Examples:

  • 0x1A3F (Hexadecimal representation of 6719 in decimal)
  • 0XFF (Hexadecimal representation of 255 in decimal)

Thus, the correct answer is (D) Both 0x and 0X.

πŸ“Š JavaScript
Q. The generalised syntax for a real number representation is
  • (A) [digits][.digits][(E|e)[(+|-)]digits]
  • (B) [digits][+digits][(E|e)[(+|-)]digits]
  • (C) [digits][(E|e)[(+|-)]digits]
  • (D) [.digits][digits][(E|e)[(+|-)]digits]
πŸ’¬ Discuss
βœ… Correct Answer: (A) [digits][.digits][(E|e)[(+|-)]digits]

Explanation:

A real number (floating-point number) in most programming languages follows this general format:

  1. [digits] β†’ Represents the integer part (optional).
  2. [.digits] β†’ Represents the fractional part (optional).
  3. [(E|e)[(+|-)]digits] β†’ Represents the exponent notation (optional).

This allows real numbers to be written in different forms, such as:

  • 123.456 (Normal decimal representation)
  • 0.789 (Starts with a decimal point)
  • 123E4 (Scientific notation, equivalent to 123 Γ— 10⁴)
  • 3.14e-2 (Equivalent to 3.14 Γ— 10⁻²)

Thus, option (A) [digits][.digits][(E|e)[(+|-)]digits] correctly represents the general syntax for real number representation.

πŸ“Š JavaScript
Q. When there is an indefinite or an infinity value during an arithmetic value computation, javascript
  • (A) Prints an exception error
  • (B) Prints an overflow error
  • (C) Displays β€œInfinity”
  • (D) Prints the value as such
πŸ’¬ Discuss
βœ… Correct Answer: (C) Displays β€œInfinity”

Explanation:

In JavaScript, when an arithmetic operation results in an infinite value (e.g., division by zero or exceeding the largest representable number), JavaScript does not throw an error. Instead, it represents the result as Infinity or -Infinity, depending on the sign of the operation.

Examples:

console.log(1 / 0);    // Output: Infinity
console.log(-1 / 0); // Output: -Infinity
console.log(10 ** 1000); // Output: Infinity (Number too large)
console.log(-10 ** 1000); // Output: -Infinity

This behavior ensures that JavaScript handles extreme values gracefully without stopping the execution of the script.

πŸ“Š JavaScript
Q. The enumeration order becomes implementation dependent and non-interoperable if:
  • (A) The delete keyword is never used
  • (B) Object.defineProperty() is not used
  • (C) If the object inherits enumerable properties
  • (D) The object does not have the properties present in the integer array indices
πŸ’¬ Discuss
βœ… Correct Answer: (C) If the object inherits enumerable properties

Explanation:

In JavaScript, the enumeration order of object properties is well-defined for own properties but can become implementation-dependent and non-interoperable when inherited properties (i.e., properties from the prototype chain) are enumerable.

  • If an object inherits enumerable properties, their enumeration order is not guaranteed to be consistent across different JavaScript engines.
  • Different JavaScript engines (like V8, SpiderMonkey, and Chakra) may handle the order of inherited properties differently, leading to inconsistencies in enumeration order.

Thus, option (C) is correct.

πŸ“Š JavaScript
Q. What happens in the following javascript code snippet?
Code:
var num = 1;
while (num < 15) 
{
     console.log(num);
     num++;
}
  • (A) An exception is thrown
  • (B) An error is displayed
  • (C) The values of count are logged or stored in a particular location or storage
  • (D) The value of count from 1 to 14 is displayed in the console
πŸ’¬ Discuss
βœ… Correct Answer: (D) The value of count from 1 to 14 is displayed in the console

Explanation:

Let's analyze the JavaScript code snippet:

var num = 1;
while (num < 15)
{
console.log(num);
num++;
}
  • The while loop starts with num = 1.
  • The condition num < 15 is true initially.
  • Inside the loop, console.log(num) prints the current value of num.
  • Then, num++ increments num by 1 after each iteration.
  • The loop continues until num reaches 15, at which point the condition num < 15 becomes false, and the loop stops.
  • Therefore, the numbers from 1 to 14 will be printed in the console.

Thus, option (D) is correct.

πŸ“Š JavaScript
Q. In the below switch syntax, the expression is compared with the case labels using which of the following operator(s)?
Code:
switch(expression)
{
    statements
}
  • (A) ===
  • (B) equal
  • (C) equals
  • (D) ==
πŸ’¬ Discuss
βœ… Correct Answer: (A) ===

Explanation:

Actually, the correct answer depends on the JavaScript version.

  • In modern JavaScript (ES6 and later), the switch statement uses strict equality (===) for comparison.
  • In older JavaScript versions (before ES6), it used loose equality (==), allowing type coercion.

Final Answer:

βœ… (A) === (for modern JavaScript)

Example (Modern JavaScript - === used)

let num = "5";

switch (num) {
case 5:
console.log("Matched with 5");
break;
case "5":
console.log("Matched with '5'");
break;
default:
console.log("No match");
}

Output:

Matched with '5'

βœ… Here, only the exact type match ("5" with "5") works, proving that === is used in modern JS.

πŸ“Š JavaScript
Q. The β€œvar” and β€œfunction” are __________.
  • (A) Prototypes
  • (B) Data types
  • (C) Keywords
  • (D) Declaration statements
πŸ’¬ Discuss
βœ… Correct Answer: (D) Declaration statements

Explanation:

var is used to declare variables.

  • function is used to declare functions.

Both are declaration statements because they define variables and functions before execution.

Example:

var x = 10;  // Variable declaration
function greet() { // Function declaration
console.log("Hello!");
}

Why Not Other Options?

  • (A) Prototypes β†’ Incorrect. Prototypes are used in object-oriented JavaScript but var and function are not prototypes.
  • (B) Data types β†’ Incorrect. var and function are not data types like string, number, etc.
  • (C) Keywords β†’ Partially correct, but they are mainly declaration statements, not just reserved words.

πŸ“Š JavaScript
Q. When an empty statement is encountered, a JavaScript interpreter
  • (A) Throws an error
  • (B) Shows a warning
  • (C) Ignores the statement
  • (D) Prompts to complete the statement
πŸ’¬ Discuss
βœ… Correct Answer: (C) Ignores the statement

Explanation:

In JavaScript, an empty statement (a semicolon ; with no associated code) is completely ignored by the interpreter. It does not cause an error or warning.

Example:

;;;
console.log("Hello, World!");
  • The semicolons (;;;) are empty statements, but they are ignored.
  • The code runs without any issues and prints "Hello, World!".

Why Not Other Options?

  • (A) Throws an error β†’ Incorrect. JavaScript does not throw an error for empty statements.
  • (B) Shows a warning β†’ Incorrect. No warnings are generated for empty statements.
  • (D) Prompts to complete the statement β†’ Incorrect. JavaScript does not prompt the user for incomplete code; it simply ignores empty statements.

πŸ“Š JavaScript
Q. What is block statement in JavaScript?
  • (A) block that combines multiple statements into a single compound statement
  • (B) both conditional block and single statement
  • (C) block that contains a single statement
  • (D) conditional block
πŸ’¬ Discuss
βœ… Correct Answer: (A) block that combines multiple statements into a single compound statement

Explanation:

A block statement (or compound statement) in JavaScript is used to group multiple statements together within curly braces {}. It is typically used in control structures like if, for, while, and function definitions.

Example of a Block Statement:

{
let a = 10;
let b = 20;
console.log(a + b); // 30
}
  • The {} braces group the let declarations and console.log() into a single block.
  • The block does not affect execution unless used in a specific context (like inside an if or loop).

Why Not Other Options?

  • (B) Both conditional block and single statement β†’ Incorrect. A block statement can contain multiple statements, not just a single statement.
  • (C) Block that contains a single statement β†’ Incorrect. A block is meant to group multiple statements, although it can contain just one.
  • (D) Conditional block β†’ Incorrect. A block can be used inside conditionals, but it is not limited to them.