16). JavaScript Code can be called by using ___________
[A]RMI
[B]Triggering Event
[C]Preprocessor
[D]Function/Method
Show Answer
Correct Answer: Function/Method
Notes:
Answer: d
Explanation: JavaScript code can be called by making a function call to the element on which JavaScript has to be run. There are many other methods like onclick, onload, and onsubmit etc.
17). The type of a variable that is volatile is _______________
[A]Volatile variable
[B] Mutable variable
[C]Immutable variable
[D]Dynamic variable
Show Answer
Correct Answer: Mutable variable
Notes:
Answer: b
Explanation: The variables whose values can be changed are called mutable variable types. In JavaScript, only objects and arrays are mutable, not primitive values.
18). A hexadecimal literal begins with __________
[A] 00
[B]0x
[C]0X
[D]Both 0x and 0X
Show Answer
Correct Answer: Both 0x and 0X
Notes:
Answer: d Explanation: Generally, X or x denotes hexadecimal values. So, any integer literal that begins with 0X or 0x denotes a hexadecimal number.
19). 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]
Show Answer
Correct Answer: [digits][.digits][(E|e)[(+|-)]digits]
Notes:
Answer: a
Explanation: Floating-point literals may also be represented using exponential notation: a real number followed by the letter e (or E), followed by an optional plus or minus sign, followed by an integer exponent. This notation represents the real number multiplied by 10 to the power of the exponent.
20). JavaScript _________ when there is an indefinite or an infinite value during an arithmetic computation.
[A]Prints an exception error
[B]Prints an overflow error
[C]Displays “Infinity”
[D]Prints the value as such
Show Answer
Correct Answer: Displays “Infinity”
Notes:
Answer: c
Explanation: When the result of a numeric operation is larger than the largest representable number (overflow), JavaScript prints the value as Infinity. Similarly, when a negative value becomes larger than the largest representable negative number, the result is negative infinity. The infinite values behave as you would expect: adding, subtracting, multiplying, or dividing them by anything results in an infinite value (possibly with the sign reversed).
21). Which of the following is not considered as an error in JavaScript?
[A]Syntax error
[B]Missing of semicolons
[C]Division by zero
[D] Missing of Bracket
Show Answer
Correct Answer: Division by zero
Notes:
Answer: c
Explanation: Division by zero is not an error in JavaScript: it simply returns infinity or negative infinity. There is one exception, however: zero divided by zero does not have a well defined value, and the result of this operation is the special not-a-number value, printed as NaN.
22). The escape sequence ‘\f’ stands for _________
[A]Floating numbers
[B]Representation of functions that returns a value
[C]\f is not present in JavaScript
[D] Form feed
Show Answer
Correct Answer: Form feed
Notes:
Answer: d
Explanation: \f is the JavaScript escape sequence that stands for Form feed (\u000C). It skips to the start of the next page. (Applies mostly to terminals where the output device is a printer rather than a VDU).
23). The snippet that has to be used to check if “a” is not equal to “null” is _________
[A] if(a!=null)
[B]if (!a)
[C] if(a!null)
[D]if(a!==null)
Show Answer
Correct Answer: if(a!==null)
Notes:
Answer: d
Explanation: A strict comparison (e.g., ===) is only true if the operands are of the same type and the contents match. The more commonly-used abstract comparison (e.g. ==) converts the operands to the same type before making the comparison. The not-equal operator !== compares 0 to null and evaluates to either true or false.
24). The statement a===b refers to _________
[A]Both a and b are equal in value, type and reference address
[B]Both a and b are equal in value
[C]Both a and b are equal in value and type
[D]There is no such statement
Show Answer
Correct Answer: Both a and b are equal in value and type
Notes:
Answer: c
Explanation: ”===” operator is known as the strict comparison operator. A strict comparison (===) is only true if the operands are of the same type and the contents match.
25). 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]false.toString()
[B]String(false)
[C]String newvariable=”false”
[D] Both false.toString() and String(false)
Show Answer
Correct Answer: Both false.toString() and String(false)
Notes:
Answer: d
Explanation: The three approaches for converting to string are: value.toString(),”” + value and String(value). A non-string can be converted in two ways without using a new operator false.toString () and String(false).
26). What will be the output of the following JavaScript code?
function compare()
{
int num=2;
char b=2;
if(a==b)
return true;
else
return false;
}
[A]true
[B]false
[C]runtime error
[D]compilation error
Show Answer
Correct Answer: true
Notes:
Answer: a
Explanation: The == convert different type of operands to the same type before making the comparison. A strict comparison results into true value if the operands are of the same type and the contents match.
27). What will be the output of the following JavaScript code?
function equalto()
{
let num=10;
if(num===”10”)
return true;
else
return false;
}
[A]true
[B]false
[C]runtime error
[D]compilation error
Show Answer
Correct Answer: false
Notes:
Answer: b
Explanation: A === operator is only true if the operands are of the same type and the contents match. Two strings are strictly equal when they have the same sequence of characters, same length, and same characters in corresponding positions.
28). What will be the output of the following JavaScript code?
function compare()
{
int a=1;
char b=1;
if(a.tostring()===b)
return true;
else
return false;
}
[A]true
[B]false
[C] runtime error
[D]logical error
Show Answer
Correct Answer: true
Notes:
Answer: a
Explanation: A non string (integer) can be converted to string using .tostring() function. A strict comparison is only true if the operands are of the same type and the contents match. Hence the following code snippet would result into true output.
29). What will be the output of the following JavaScript code?
int a==2;
int b=4;
int ans=a+b;
print(ans);
Show Answer
Correct Answer: error
Notes:
Answer: d
Explanation: The following code will generate into an error output as a comparator operator is used outside of if statement. A single equalto (’=’) operator is used for initialization.
30). What will be the output of the following JavaScript code?
int a=1;
if(a!=null)
return 1;
else
return 0;
[A]1
[B]0
[C] runtime error
[D]compiler error
Show Answer
Correct Answer: 1
Notes:
Answer: a
Explanation: != is the not equal to operator. It gives a value of 1 if the two values which are compared are not equal and give 0 if the two values are equal.