Essential JavaScript Interview Question 1658482928
Essential JavaScript Interview Question 1658482928
JavaScript
Interview
Question
What is a potential pitfall with using
typeof bar === "object" to determine if
bar is an object? How can this pitfall be
avoided?
Although typeof bar === "object" is a reliable way of checking
if bar is an object, the surprising gotcha in JavaScript is that
null is also considered an object!
ES5 makes the array case quite simple, including its own null
check:
console.log(Array.isArray(bar));
Follow AI Arif for MORE