Introduction
Namaste, In this blog I will discuss 7 code scenarios on Javascript fundamentals.
Identify the output of the below program
let sym = Symbol(); if (sym) console.log("true"); else console.log("false");
a.undefined
b.null
c.true
d. false
e.error
Answer: c
Reason: Symbol is a truthy value.
Identify the output of the below program
if (function fx(){}) console.log("true"); else console.log("false");
a.false
b.error
c.undefined
d. true
e.null
Answer: d
Reason: A function is a truthy value.
Identify the output of the below program
if (Object) console.log("true"); else console.log("false");
a.false
b.error
c.null
d. undefined
e.true
Answer: e
Reason: The Object is pre-defined and any object is truthy.
Identify the output of the below program
if (" ") console.log("true"); else console.log("false");
a.error
b.true
c.false
d.undefined
e.null
Answer:b
Reason: String with space is truthy.
Identify the output of the below program
let fx = function(){} if (fx) console.log("true"); else console.log("false");
a.false
b.error
c.true
d. undefined
e.0
Answer: c
Reason: A function is a truthy value.
Identify the output of the below program
console.log( typeof "");
a. undefined
b.null
c.string
d. NaN
e.error
Answer: c
Reason: Empty double quotes are a string type.
Identify the output of the below program
let cls = class My{}; if (cls) console.log("true"); else console.log("false");
a.error
b.undefined
c.false
d. true
e.null
Answer: d
Reason: A class is a truthy value.