49). JavaScript is a _______________ language.
[A]Object-Oriented
[B]High-level
[C]Assembly-language
[D]Object-Based
Show Answer
Correct Answer: Object-Based
Notes:
Answer: d
Explanation: JavaScript is not a full-blown OOP (Object-Oriented Programming) language, such as Java or PHP, but it is an object-based language. The criteria for object orientation are the classic threesome of polymorphism, encapsulation and inheritance and JavaScript doesn’t pass this.
50). What will be the output of the following JavaScript code?
var a=5 , b=1
var obj = { a : 10 }
with(obj)
{
alert(b)
}
Show Answer
Correct Answer: 1
Notes:
Answer: c
Explanation: Firstly the interpreter checks obj for property b. But it doesn’t find any property b so it takes the value from outside the object within the code snippet.
51). A conditional expression is also called a _______________
var a=5 , b=1
var obj = { a : 10 }
with(obj)
{
alert(b)
}
[A]Alternative to if-else
[B] Immediate if
[C]If-then-else statement
[D]Switch statement
Show Answer
Correct Answer: Immediate if
Notes:
Answer: b
Explanation: A conditional expression can evaluate to either True or False based on the evaluation of the condition. If the condition is true then the value following the operator is taken that’s why it is called immediate if.
52). Which is a more efficient JavaScript code snippet?
Code 1 :
for(var num=10;num>=1;num--)
{
document.writeln(num);
}Code 2 :var num=10;
while(num>=1)
{
document.writeln(num);
num++;
}
[A]Code 1
[B]Code 2
[C]Both Code 1 and Code 2
[D]Cannot Compare
Show Answer
Correct Answer: Code 1
Notes:
Answer: a
Explanation: Code 1 would be more efficient. Infact second code will go into runtime error as the value of num will never reach less than or equal to one.
53). What is a block statement in JavaScript?
Code 1 :
for(var num=10;num>=1;num--)
{
document.writeln(num);
}Code 2 :var num=10;
while(num>=1)
{
document.writeln(num);
num++;
}
[A]conditional block
[B] block that contains a single statement
[C]both conditional block and a single statement
[D] block that combines multiple statements into a single compound statement
Show Answer
Correct Answer: block that combines multiple statements into a single compound statement
Notes:
Answer: d
Explanation: A block statement groups zero or more statements. In languages other than JavaScript, it is known as a compound statement. A statement block is a block that combines more than one statements into a single compound statement for ease.
54). When an empty statement is encountered, a JavaScript interpreter __________
Code 1 :
for(var num=10;num>=1;num--)
{
document.writeln(num);
}Code 2 :var num=10;
while(num>=1)
{
document.writeln(num);
num++;
}
[A] Ignores the statement
[B]Prompts to complete the statement
[C]Throws an error
[D]Shows a warning
Show Answer
Correct Answer: Ignores the statement
Notes:
Answer: a
Explanation: The JavaScript interpreter takes no action when it executes an empty statement. The empty statement is occasionally useful when you want to create a loop that has an empty body.
55). The “var” and “function” are __________
Code 1 :
for(var num=10;num>=1;num--)
{
document.writeln(num);
}Code 2 :var num=10;
while(num>=1)
{
document.writeln(num);
num++;
}
[A]Keywords
[B]Declaration statements
[C]Data types
[D]Prototypes
Show Answer
Correct Answer: Declaration statements
Notes:
Answer: b
Explanation: The var and function are declaration statements—they declare or define variables and functions. These statements define identifiers (variable and function names) that can be used elsewhere in your program and assign values to those identifiers.
56). In the following switch syntax, the expression is compared with the case labels using which of the following operator(s)?
switch(expression)
{
statements
}
[A]==
[B]equals
[C]equal
[D]===
Show Answer
Correct Answer: ===
Notes:
Answer: d
Explanation: A strict comparison (e.g., ===) is only true if the operands are of the same type and the contents match. When a switch executes, it computes the value of the expression and then looks for a case label whose expression evaluates to the same value (where sameness is determined by the === operator).
57). What happens in the following javaScript code snippet?
var count = 0;
while (count < 10)
{
console.log(count);
count++;
}
[A]The values of count are logged or stored in a particular location or storage
[B]The value of count from 0 to 9 is displayed in the console
[C]An error is displayed
[D]An exception is thrown
Show Answer
Correct Answer: The value of count from 0 to 9 is displayed in the console
Notes:
Answer: b
Explanation: Console.log is a predefined function in JavaScript which takes the value as an argument of its function.console.log prints this value in the argument in the console at the time of execution of the code.
58). The enumeration order becomes implementation dependent and non-interoperable if ___________
var count = 0;
while (count < 10)
{
console.log(count);
count++;
}
[A] If the object inherits enumerable properties
[B]The object does not have the properties present in the integer array indices
[C]The delete keyword is never used
[D]Object.defineProperty() is not used
Show Answer
Correct Answer: If the object inherits enumerable properties
Notes:
Answer: a
Explanation: In computer programming, an enumerated type (also called enumeration or enum) is a data type consisting of a set of named values called elements, members or enumerators of the type. The enumerator names are usually identifiers that behave as constants in the language.
59). What will be the output of the following JavaScript code?
Int a=1;
if(a>10)
{
document.write(10);
}
else
{
document.write(a);
}
[A]10
[B]0
[C]1
[D]Undefined
Show Answer
Correct Answer: 1
Notes:
Answer: c
Explanation: The if else statement is a part of the javascript conditioning statements. The line of code inside the “if” statement is executed if the value passed to “if” is 1.
60). What will be the output of the following JavaScript code?
var grade='B';
var result;
switch(grade)
{
case 'A':
{
result+="10";
break;
}
case 'B':
{
result+=" 9";
break;
}
case 'C':
{
result+=" 8";
break;
}
default:
result+=" 0";
}
document.write(result);
Show Answer
Correct Answer: 9
Notes:
Answer: b
Explanation: The above code contains a switch loop. It is used as an alternative to if else statement. One of the given condition is satisfied according to the input of the switch case and the output is decided accordingly.
61). What will be the output of the following JavaScript code?
var grade='A';
var result;
switch(grade)
{
case 'A':
result+="10";
case 'B':
result+=" 9";
case 'C':
result+=" 8";
default:
result+=" 0";
}
document.write(result);
Show Answer
Correct Answer: 27
Notes:
Answer: b
Explanation: The above code does not have a break statement after the cases in the switch loop. Therefore all of the cases following “A” will get executed.
62). What will be the output of the following JavaScript code?
int a=4;
int b=1;
int c=0;
If(a==b)
document.write(a);
else if(a==c)
document.write(a);
else
document.write(c);
Show Answer
Correct Answer: 0
Notes:
Answer: d
Explanation: For checking more than one condition the if else if loop is used. It is the extension of if else loop which is also sometimes known as if else ladder.
63). What will be the output of the following JavaScript code?
var grade='E';
var result;
switch(grade)
{
case 'A':
result+="10";
case 'B':
result+=" 9";
case 'C':
result+=" 8";
default:
result+=" 0";
}
document.write(result);
Show Answer
Correct Answer: 0
Notes:
Answer: b
Explanation: The switch case contains a default case along with the other cases. The default case gets executed when no other case results into true.