90% failed to answer these tricky javascript snippets

Vineet Mishra
Jan 9, 2023

--

Q1. Guess the output

var x=0
x++
x=’vineet’
x=true
console.log(`Value of x ${x} ,\n type of x ${typeof(x)}`)

Take a breath, Don’t jump into solution

Output: 
Value of x true ,
type of x boolean

Q2. Guess the output

const compact = arr => console.log(arr.filter(Boolean));
compact([0, 1, false, 2, ‘’, 3, ‘a’, ‘e’ * 23, NaN, ‘s’, 34])

Take a breath, Don’t jump into solution

Output:
[ 1, 2, 3, 'a', 's', 34 ]

--

--

Vineet Mishra
Vineet Mishra

Written by Vineet Mishra

SDE 2 at Accelya , I write about Mobile/Web Development and Deployment, and Interview Q & A

No responses yet