Test your JavaScript Skills:Fundamentals-17
Part 17
Introduction
Namaste, In this blog I will discuss 7 code scenarios on Javascript fundamentals.
Identify the output of the below program
let a=10; const a=11; console.log("value", a);
a.10
b.11
c.error
d.undefined
e.null
Answer:c
Reason: There is an error because of re-declaration.
Identify the output of the below program
function fx() {} var fx=10; console.log("value", fx);
a.10
b.fx(){}
c.undefined
d.error
e.null
Answer: a
Reason: There is no re-declaration hence fx takes the last assigned value i.e. 10.
Identify the output of the below program
let fx4=1; function fx4(){} console.log("value", fx4)
a.error
b.null
c.undefined
d.1
e.fx4(){}
Answer: a
Reason: There is an error because of re-declaration
Identify the output of the below program
var fx5=56; function fx5(){ console.log("fx5"); } console.log(typeof fx5);
a.56
b.function
c.number
d.error
e.undefined
Answer: c
Reason: The typeof of fx5 is a number.
Identify the output of the below program
function fx() {} let fx=30; console.log("value", fx);
a.error
b.30
c.fx(){}
d.undefined
e.null
Answer: a
Reason: There is an error because of re-declaration.
Identify the output of the below program
var fx5; function fx5(){ console.log("fx5"); } console.log(typeof fx5);
a. function
b. number
c. undefined
d. error
e. class
Answer: a
Reason: The typeof of fx5 is function.
Identify the output of the below program
function fx3(){} const fx3=30; console.log("value", fx3);
a.fx3(){}
b.30
c.undefined
d.error
e.null
Answer: d
Reason: There is an error because of re-declaration.