Javascript Fundamentals MCQ
This section focuses on the "Javascript Fundamentals" of the Javascript. These Multiple Choice Questions (mcq) should be practiced to improve the Javascript skills required for various interviews (campus interview, walk-in interview, company interview), placement, entrance exam and other competitive examinations.
1. Which of the following is a JavaScript data type?
A. null
B. undefined
C. object
D. All of the above
View Answer
Ans : D
Explanation: Null,Undefined,Object are the following is a JavaScript data type.
2. What will be the output of the below code ?
console.log( typeof( '5' + 5))
A. number
B. string
C. object
D. null
View Answer
Ans : B
Explanation: string will be the output of the below code
3. What will be the output of the below code ?
var package;
console.log("Package: " + package)
console.log("Amount: " + amount);
A. Package: null; Amount: null;
B. Package: undefined; Amount: undefined;
C. Package: null; An ReferenceError is thrown saying amount is not defined;
D. Package: undefined; An ReferenceError is thrown saying amount is not defined;
View Answer
Ans : D
Explanation: Package: undefined; An ReferenceError is thrown saying amount is not defined; is the output of the below code
4. What will be the output of the below code ?
var i=true;
var j=false;
var k=true;
if( i || J && K){
a=10;
b="True";
}
else {
a=20;
b="False";
}
console.log(a+","+b);
A. 10,True
B. 10,False
C. 20,True
D. 20,False
View Answer
Ans : A
Explanation: 10,True will be the output of the below code
5. The statement is an example of:
while (3==3) {}
A. A typographical error
B. An infinite loop
C. An illegal JavaScript statement
D. None of the above
View Answer
Ans : B
Explanation: The statement is an example of:An infinite loop.
6. Which of the following is a syntactically correct for loop?
A. for (i<=10;i++)
B. for i=1 to 10
C. for (i=0;i<=10;i++)
D. for (i=0;i<=10)
View Answer
Ans : C
Explanation: for (i=0;i<=10;i++) following is a syntactically correct for loop.
7. What are the three important manipulations done in a for loop on a loop variable?
A. Initialization,Testing, Incrementation
B. Updation, Incrementation, Initialization
C. Initialization,Testing, Updation
D. Testing, Updation, Testing
View Answer
Ans : C
Explanation: In a for loop, the initialization, the test, and the update are the three crucial manipulations of a loop variable. Firstly the loop initialiases the variable then test the condition and then after executing the statement increments its value.
8. What will the following JavaScript code snippet do? If not, what will be the error?
function letsfindcourse(lfc)
{
for (; lfc.next; lfc = lfc.next) ;
return lfc;
}
A. No, this will result in a runtime error with the message Cannot use Linked List
B. No, this will not iterate
C. Yes, this will work
D. No, this will throw an exception as only numerics can be used in a for loop
View Answer
Ans : C
Explanation: The above code uses a for loop to traverse a linked list data structure and return the last object in the list. This will perfectly work.
9. What will be the output of the following JavaScript code?
function fun_range(int l)
{
int p=2;
for(int x=0;x
{
console.log(p);
}
}
range(4);
A. 2
B. 2222
C. 4
D. error
View Answer
Ans : B
Explanation: for loop first initializes the variable and later on checks for the condition expression and after that execute the line of statements. The value of iterator x increase until it reaches the value of length l.
10. What will be the output of the following JavaScript code?
int x=0;
for(x;x<10;x++);
console.log(x);
A. 0
B. 9
C. 10
D. error
View Answer
Ans : C
Explanation: The value of the x will increases until it becomes equal to 10, after which the cursor comes out of the loop. There are no statements for the loop so only the value of one will increase. Therefore the output will be 10.
Also check :
Discussion