Prepare for the Salesforce JavaScript Developer Exam. Utilize comprehensive quizzes, flashcards, and multiple choice questions with hints and explanations. Boost your exam readiness!

Practice this question and more.


Which of the following values are considered falsy in JavaScript?

  1. 0, '', undefined

  2. 0, new Number(0), '', new Boolean(false), undefined

  3. 0, '', new Boolean(false), undefined

  4. All of them are falsy

The correct answer is: 0, '', undefined

In JavaScript, the concept of "falsy" values refers to values that evaluate to false in a boolean context. The values considered falsy include 0 (the number zero), an empty string (''), null, undefined, and NaN (Not-a-Number). The correct answer identifies that 0, '', and undefined are indeed falsy values. When examining the other choices, it's important to note that new Number(0) and new Boolean(false) are not falsy because they are objects. In JavaScript, all objects are truthy regardless of their content unless they are explicitly checked for their primitive value. While the primitive number 0 and the primitive boolean false are falsy, their object counterparts (new Number(0) and new Boolean(false)) return true in conditions since they are objects. Therefore, the correct selection showcases only the universally recognized falsy values without including any that could be considered truthy due to being objects. This understanding helps in accurately determining the behavior of different types of data in JavaScript.