Introduction
Namaste, In this blog I will discuss 7 code scenarios on Javascript fundamentals.
Identify the output of the below program
console.log({no:100} + null );
a.error
b.{no:100}0
c.{no:100}1
d.{no:100}null
e.[object Object]null
Answer: e
Reason: The object is converted to a string which is concatenated with null.
Identify the output of the below program
var i=10; let i=30; console.log("value",i);
a.10
b.30
c.error
d.undefined
e.null
Answer: c
Reason: There is an error because of re-declaration.
Identify the output of the below program
var k=10; const k=20; console.log("value", k);
a.null
b.20
c.10
d.undefined
e.error
Answer:e
Reason: There is an error because of re-declaration.
Identify the output of the below program
if ("ram"+undefined) console.log("true"); else console.log("false");
a.true
b.false
c.undefined
d.null
e.error
Answer: a
Reason: The string is concatenated with undefined hence condition is true.
Identify the output of the below program
console.log({no:10} + {name:"ram"});
a. error
b.true
c.[no:10] [name: "ram"]
d.[object Object] [object Object]
e.{no:10} {name:"ram"}
Answer: d
Reason: Both objects are converted to a string and concatenated.
Identify the output of the below program
let j=10; var j=30; console.log("value",j);
a.30
b.10
c.undefined
d.null
e.error
Answer: e
Reason: There is an error because of re-declaration.
Identify the output of the below program
console.log({no:10});
a.[object Object]
b.error
c.{no:10}
d.undefined
e.object
Answer: c
Reason: The object is displayed as it is.