Skip to content
Related Articles

Related Articles

Improve Article
Save Article
Like Article

Aptitude | JavaScript Course Quiz 3 | Question 5

  • Last Updated : 10 May, 2019

What will be the output of the following code?

let bar  = 1;
foo = {};
foo: {
     bar : 2;
     baz : ++bar;
document.write(foo.baz + + bar);

(A) NaN
(B) 5
(C) 4
(D) 1

Answer: (A)

Explanation: It’s not actually altering the variable foo. Here the text foo is part of a label, and the object that follows is called a javascript block and it contains two labeled statements, not variable assignments. That leaves us with two undefined variables added to 1. Which is NaN. If the variable bar was not declared higher in the code this object would kick out a syntax error as bar would be undefined.

Quiz of this Question

My Personal Notes arrow_drop_up
Recommended Articles
Page :