Q. If the following piece of JavaScript code is executed, will it work if not, what kind of possible error can occur?

Code:
function fun(o)  
{  
for(;o.next; oo =o.next);  
return o;  
} 
  • (A) Yes, it will work fine
  • (B) No, this will not iterate at all
  • (C) No, it will throw an exception as only numeric's can be used in a for loop
  • (D) No, it will produce a runtime error with the message "Cannot use Linked List"
πŸ’¬ Discuss
βœ… Correct Answer: (A) Yes, it will work fine

Q. What is the role of the "continue" keyword in the following piece of JavaScript code?

Code:
    while (x !=0)  
    {  
    if(x ==1)  
    continue;  
    else  
           x++;  
    }  
  • (A) The continue keyword skips the next iteration
  • (B) The continue keyword restarts the loop
  • (C) It is used for skipping the rest of the statements in that particular iteration
  • (D) The "continue" keyword breaks out of the loop
πŸ’¬ Discuss
βœ… Correct Answer: (C) It is used for skipping the rest of the statements in that particular iteration
Explanation:

Let's solve it carefully.

In this JavaScript code:

while (x != 0)  
{
if (x == 1)
continue;
else
x++;
}
  • When continue is encountered, it immediately skips the rest of the statements inside the loop for that particular iteration and jumps to the next iteration.
  • It does not break the loop (unlike break).
  • It does not restart the loop from the beginning; it just moves to the next cycle.

Thus:

The "continue" keyword is used for skipping the rest of the statements in that particular iteration.

Final Answer:

(C) It is used for skipping the rest of the statements in that particular iteration

Q. Which one of the following is not considered as "statement" in the JavaScript?

  • (A) use strict
  • (B) debugger
  • (C) if
  • (D) with
πŸ’¬ Discuss
βœ… Correct Answer: (A) use strict

Q. What if we define a "for" loop and it removes one of the properties that has not yet been enumerated?

  • (A) The removed property will be stored in a cache
  • (B) The loop will not run at all
  • (C) That property will be enumerated
  • (D) That specific property will not be enumerated
πŸ’¬ Discuss
βœ… Correct Answer: (D) That specific property will not be enumerated

Q. Which of the following is the correct response by the interpreter in a jump statement when an exception is thrown?

  • (A) The interpreter will jump to the one of the nearest enclosing exception handler
  • (B) The interpreter will stop working
  • (C) The interpreter will throw another exception
  • (D) The interpreter throws an error
πŸ’¬ Discuss
βœ… Correct Answer: (A) The interpreter will jump to the one of the nearest enclosing exception handler

Q. Which one of the following is the possibly correct output for the given JavaScript code?

Code:
functionfun(int length)  
{  
    int a=5;  
    for(inti=0;i<length;i++)  
    {  
        console.log(a);  
    }  
}  
fun(2); 
  • (A) 5
  • (B) 555
  • (C) 55
  • (D) Error
πŸ’¬ Discuss
βœ… Correct Answer: (C) 55

Q. Which one of the following is the correct output for the given JavaScript code?

Code:
    var a=0;  
    var b =0;  
    while (a <3)  
    {  
        a++;  
        b += a;  
        console.log(b);  
    }  
  • (A) 136
  • (B) 123
  • (C) 013
  • (D) 01
πŸ’¬ Discuss
βœ… Correct Answer: (A) 136

Q. Which of the following options would be the correct output for the given JavaScript code?

Code:
    var size=5;  
    var x=5;  
    var size=4;  
    for(var j=size;j>=0;j--)  
    {  
        console.log(x);  
        xx=x-2;  
    }  
  • (A) 5321
  • (B) 5555
  • (C) 531-1-3
  • (D) 531
πŸ’¬ Discuss
βœ… Correct Answer: (C) 531-1-3

Q. Which of the following options would be the correct output for the given JavaScript code?

Code:
var x=0;  
for(x;x<10;x++);  
console.log(x); 
  • (A) 10
  • (B) 4
  • (C) 5
  • (D) Error
πŸ’¬ Discuss
βœ… Correct Answer: (A) 10

Q. Consider the following piece of JavaScript code:
What is the role of the "debugger" statement?

Code:
<script>  
  
function fun(0){  
    if(0===undefined)  
        debugger;  
      
}  
  
</script> 
  • (A) It will debug the error in that statement
  • (B) It is kind of keyword which is used to debug the entire program at once
  • (C) It will do nothing, although it is a breakpoint
  • (D) All of the above
πŸ’¬ Discuss
βœ… Correct Answer: (C) It will do nothing, although it is a breakpoint