Photo by Sincerely Media on Unsplash
Test Your JavaScript Skills : ES10 (JavaScript 2019) - 43
Part 43
Introduction
Namaste, In this blog I will discuss 8 code scenarios on Javascript .
Identify the output of the below program
let text = ' Namaste '; let trimmedStart = text.trimStart(); console.log(trimmedStart);
a.Namaste
b. Namaste
c.error
d.undefined
e.null
Answer:a
Reason:The spaces from starting are removed.
Identify the output of the below program
let text = ' Namaste '; const trimmedEnd = text.trimEnd(); console.log(trimmedEnd);
a.Namaste
b. Namaste
c.Namas te
d.undefined
e.error
Answer:b
Reason:The spaces from end are removed.
Identify the output of the below program
const entries = [['a', 1]]; const obj = Object.fromEntries(entries); console.log(obj);
a.['a','1']
b.{a:1}
c.{1:a}
d.['1':'a']
e.error
Answer:b
Reason:The array is converted to object.
Identify the output of the below program
const entries = ['a', 1]; const obj = Object.fromEntries(entries); console.log(obj);
a.error
b.{a:1}
c.{1:a}
d.{'a':'1'}
e.undefined
Answer:a
Reason:The input is invalid hence error.
Identify the output of the below program
const map = new Map([ ["Lang", "JS"], ]); let obj2 = Object.fromEntries(map); console.log(obj2);
a.{'Lang':'JS'}
b.{Lang:JS}
c.{Lang:'JS'}
d.{0:'JS'}
e.error
Answer:c
Reason:The Map is converted to an object.
Identify the output of the below program
const map = new Map( ["Lang", "JS"] ); let obj2 = Object.fromEntries(map); console.log(obj2);
a.{'Lang':'JS'}
b.{Lang:JS}
c.{Lang:'JS'}
d..{0:'JS'}
e.error
Answer:e
Reason:The input is invalid.
Identify the output of the below program
let mySymbol = Symbol('Database'); console.log(mySymbol.description);
a.Database
b.Symbol
c.Object
d.Symbol(Object)
e.error
Answer:a
Reason:The description property has value Database.
Identify the output of the below program
const entries = [['data', false]]; const obj = Object.fromEntries(entries); console.log(obj);
a.['data', false]
b.{'data', false}
c.['data', false]
d.{data: false}
e.undefined
Answer:d
Reason:The array is converted to an object.