πŸ“Š JavaScript
Q. A conditional expression is also called a
  • (A) If-then-else statement
  • (B) Alternative to if-else
  • (C) Immediate if
  • (D) All of above
πŸ’¬ Discuss
βœ… Correct Answer: (C) Immediate if

Explanation:

A conditional expression in JavaScript refers to the ternary operator (? :), which is also known as the "immediate if" because it provides a quick, one-line alternative to an if-else statement.

Syntax of Ternary Operator:

condition ? expression1 : expression2;
  • If condition is true, expression1 executes.
  • If condition is false, expression2 executes.

Example:

let age = 18;
let canVote = (age >= 18) ? "Yes" : "No";
console.log(canVote); // Output: "Yes"

Why Not Other Options?

  • (A) If-then-else statement β†’ Incorrect. The ternary operator is not a full if-else statement but a single expression.
  • (B) Alternative to if-else β†’ Partially correct, but the ternary operator is a shortened version of if-else, not an exact alternative in all cases.
  • (D) All of the above β†’ Incorrect. Since A and B are not fully correct, this option is also incorrect.

πŸ“Š JavaScript
Q. What would be the most appropriate output for the following code snippet?
Code:
var p=15 , q=10
var object = { p : 20 }
with(object) 
{
      alert(q)
}
  • (A) 20
  • (B) Error
  • (C) 15
  • (D) 10
πŸ’¬ Discuss
βœ… Correct Answer: (D) 10

Explanation:

The with statement in JavaScript is used to extend the scope chain for a specific object, making its properties accessible without explicitly referring to the object.

Step-by-Step Execution:

var p = 15, q = 10; // Declaring two global variables

var object = { p: 20 }; // Creating an object with a property 'p'

with (object) {
alert(q); // Attempting to access 'q'
}
  • The with(object) block adds object to the scope chain.
  • When accessing q, JavaScript first looks inside object.
  • Since q is not defined inside object, JavaScript falls back to the global scope, where q = 10.
  • So, the output will be 10.

Why Not Other Options?

  • (A) 20 β†’ Incorrect, because q is not present in object, so p: 20 has no effect.
  • (B) Error β†’ Incorrect, as q exists globally and no error occurs.
  • (C) 15 β†’ Incorrect, because p = 15 is also ignored; the focus is only on q.

Thus, the correct answer is 10.

πŸ“Š JavaScript
Q. JavaScript is a _______________ language
  • (A) Object-Based
  • (B) Assembly-language
  • (C) High-level
  • (D) Object-Oriented
πŸ’¬ Discuss
βœ… Correct Answer: (A) Object-Based

Explanation:

JavaScript is Object-Based rather than fully Object-Oriented because:

Object-Based Language

  • JavaScript uses objects extensively but does not support features like class-based inheritance (before ES6 introduced class syntax).
  • It follows prototype-based inheritance rather than classical OOP (Object-Oriented Programming).

Why Not Other Options?

  • (B) Assembly-language β†’ ❌ Incorrect, because JavaScript is a high-level language, not low-level like Assembly.
  • (C) High-level β†’ βœ… JavaScript is a high-level language, but the most precise classification is "Object-Based."
  • (D) Object-Oriented β†’ ❌ JavaScript does have OOP features (like objects and prototypes), but it lacks true class-based OOP principles like Java or C++.

Thus, JavaScript is primarily "Object-Based" because it uses objects but not full OOP features.

πŸ“Š JavaScript
Q. Assume that we have to convert β€œfalse” that is a non-string to string. The command that we use is (without invoking the β€œnew” operator)
  • (A) String newvariable=”false”
  • (B) Both false.toString() and String(false)
  • (C) String(false)
  • (D) false.toString()
πŸ’¬ Discuss
βœ… Correct Answer: (B) Both false.toString() and String(false)

Explanation:

In JavaScript, we can convert a boolean (false) to a string in two ways:

Using .toString() method

  • The .toString() method converts false to the string "false".
  • It works only if false is a primitive value, not null or undefined.

Using String() function

  • The String() function also converts false to a string.
  • It works with any value (null, undefined, numbers, booleans, etc.).

Why Not Other Options?

  • (A) String newvariable=”false” β†’ ❌ Incorrect, because this is not valid JavaScript syntax.
  • (C) String(false) β†’ βœ… Correct, but not the only correct answer.
  • (D) false.toString() β†’ βœ… Correct, but not the only correct answer.

Since both methods work, the best answer is (B) Both false.toString() and String(false).

var str2 = String(false);
console.log(str2); // Output: "false"
var str1 = false.toString();
console.log(str1); // Output: "false"

πŸ“Š JavaScript
Q. The statement p===q refers to _________
  • (A) There is no such statement
  • (B) Both p and q are equal in value, type and reference address
  • (C) Both p and q are equal in value
  • (D) Both p and q are equal in value and type
πŸ’¬ Discuss
βœ… Correct Answer: (D) Both p and q are equal in value and type

Explanation:

In JavaScript, the === (strict equality operator) checks both:

  1. Value equality (i.e., p and q must have the same value)
  2. Type equality (i.e., p and q must be of the same data type)

Example 1: Equal in Value and Type (true output)

var p = 10;
var q = 10;
console.log(p === q); // Output: true (same value and same type)

Example 2: Same Value, Different Type (false output)

var p = 10;       // Number
var q = "10"; // String
console.log(p === q); // Output: false (different types: number vs string)

Why Not Other Options?

  • (A) "There is no such statement" β†’ ❌ Incorrect, because p === q is a valid JavaScript statement.
  • (B) "Both p and q are equal in value, type, and reference address" β†’ ❌ Incorrect, because === does not compare reference addresses. It only checks value and type.
  • (C) "Both p and q are equal in value" β†’ ❌ Incorrect, because === checks both value and type, not just value.

Final Answer:

βœ… (D) Both p and q are equal in value and type.

πŸ“Š JavaScript
Q. The snippet that has to be used to check if β€œa” is not equal to β€œnull” is _________
  • (A) if(a!==null)
  • (B) if(a!null)
  • (C) if (!a)
  • (D) if(a!=null)
πŸ’¬ Discuss
βœ… Correct Answer: (A) if(a!==null)

Explanation:

In JavaScript, we use !== (strict inequality operator) to check both:

  1. Value inequality
  2. Type inequality

Example: Checking if a is not null

var a = "Hello";  // Example value
if (a !== null) {
console.log("a is not null");
} else {
console.log("a is null");
}

Output:

a is not null

If a = null, then the condition fails.

Why Not Other Options?

  • (B) if(a!null) β†’ ❌ Incorrect (invalid syntax; ! should be used with boolean expressions, not values).
  • (C) if(!a) β†’ ❌ Incorrect (this checks if a is falsy, but 0, "", undefined, NaN, and false are also falsy, not just null).
  • (D) if(a != null) β†’ βœ… Correct, but (A) is preferred because != does type coercion, whereas !== strictly checks for null.

Final Answer:

βœ… (A) if(a !== null) (Best practice for checking null).

πŸ“Š JavaScript
Q. The escape sequence β€˜\f’ stands for _________
  • (A) Form feed
  • (B) \f is not present in JavaScript
  • (C) Representation of functions that returns a value
  • (D) Floating numbers
πŸ’¬ Discuss
βœ… Correct Answer: (A) Form feed

Explanation:

In JavaScript, the escape sequence \f stands for Form Feed. It is a control character used in old printers to signal a page break. However, in modern JavaScript applications, it is rarely used and often ignored by modern browsers and text processors.

Example in JavaScript:

console.log("Hello\fWorld");

Output (may vary depending on the console):

HelloWorld

(The \f may not be visible in many text editors.)

Why Not Other Options?

  • (B) \f is not present in JavaScript β†’ ❌ Incorrect (It does exist in JavaScript).
  • (C) Representation of functions that return a value β†’ ❌ Incorrect (\f is not related to functions).
  • (D) Floating numbers β†’ ❌ Incorrect (\f has nothing to do with floating-point numbers).

Final Answer:

βœ… (A) Form feed

πŸ“Š JavaScript
Q. Which of the following is not considered as an error in JavaScript?
  • (A) Missing of Bracket
  • (B) Syntax error
  • (C) Missing of semicolons
  • (D) Division by zero
πŸ’¬ Discuss
βœ… Correct Answer: (D) Division by zero

Explanation:

In JavaScript, dividing a number by zero does not throw an error. Instead, it returns Infinity (or -Infinity for negative numbers). JavaScript handles division by zero gracefully, unlike some other languages where it may cause an error.

Example:

console.log(10 / 0);  // Output: Infinity
console.log(-10 / 0); // Output: -Infinity

However, if the value is 0/0, it results in NaN (Not-a-Number):

console.log(0 / 0); // Output: NaN

Why Not Other Options?

  • (A) Missing of Bracket β†’ ❌ Error (Missing brackets can cause syntax errors).
  • (B) Syntax error β†’ ❌ Error (Incorrect syntax results in a SyntaxError).
  • (C) Missing of semicolons β†’ ❌ Error (Although JavaScript has automatic semicolon insertion, in some cases, missing semicolons can lead to unexpected behavior or errors).

Final Answer:

βœ… (D) Division by zero (It returns Infinity instead of throwing an error).

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

Explanation:

In JavaScript, when an arithmetic computation results in an indefinite or infinite value, JavaScript does not throw an error. Instead, it returns Infinity (or -Infinity for negative values).

Example:

console.log(10 / 0);  // Output: Infinity
console.log(-10 / 0); // Output: -Infinity

If the result of a computation is undefined (like 0/0), JavaScript returns NaN (Not-a-Number):

console.log(0 / 0); // Output: NaN

Why Not Other Options?

  • (A) Prints the value as such β†’ ❌ Incorrect (JavaScript does not print raw values; instead, it handles them specifically as Infinity).
  • (B) Prints an exception error β†’ ❌ Incorrect (JavaScript does not throw an exception for division by zero).
  • (C) Prints an overflow error β†’ ❌ Incorrect (JavaScript does not have an "overflow error" like some other languages).

Final Answer:

βœ… (D) Displays β€œInfinity”

πŸ“Š JavaScript
Q. JavaScript Code can be called by using
  • (A) Preprocessor
  • (B) Function/Method
  • (C) RMI
  • (D) Triggering Event
πŸ’¬ Discuss
βœ… Correct Answer: (B) Function/Method

Explanation:

In JavaScript, code can be executed in multiple ways, but the most common and structured way is through functions or methods. A function is a reusable block of code that performs a specific task when called.

Example of Calling JavaScript Code Using a Function:

function greet() {
console.log("Hello, World!");
}
greet(); // Calling the function

Why Not Other Options?

(A) Preprocessor β†’ ❌ Incorrect
JavaScript is an interpreted language, meaning it does not require preprocessing like languages such as C or C++.

(C) RMI (Remote Method Invocation) β†’ ❌ Incorrect
RMI is a Java-based technology used for remote procedure calls, not for JavaScript execution.

(D) Triggering Event β†’ ❌ Partially Correct
Events like onClick, onLoad, etc., can execute JavaScript, but they usually call functions to perform the actual logic.

Final Answer:

βœ… (B) Function/Method