MSK Institute LogoMSK.Institute
HomeCourses
Book Free Demo➔Sign In
Free Demo➔
MSK Institute LogoMSK.Institute

Leading computer training academy in Shikohabad for software engineering, Python, web development, and digital literacy.

ISO 9001:2015 Certified Center
Follow & Connect
4.9

Programs & Admissions

  • All CoursesCatalog
  • Learning PathsRoadmaps
  • Student ProjectsShowcase
  • Live Classes & ScheduleLive
  • Upcoming Batches
  • Campuses & LocationsHub
  • Verify Certificates
  • Book Free Demo Class

Resources & Tools

  • Free Online Mock TestsAll Tests
  • NIELIT CCC Mock TestFree
  • Course & Career FinderQuiz
  • Study Material Hub
  • All MSK ToolsHub
  • Keyboard ShortcutsNew
  • TypeQuest Speed LabTyping
  • MSK Code PlaygroundCode
  • Interactive Tutorials
  • Quick Cheatsheets

Institute & Contact

  • About MSK Institute
  • Careers & InternshipsHiring
  • Publications & Blogs
  • Gali No. 3, Near Gyan Jyoti Public School,
    Adarsh Nagar, Shikohabad, Uttar Pradesh 283135
  • +91 83930 42166
  • mskshikohabad@gmail.com
  • Hours:Mon – Sat: 8:00 AM – 7:00 PM | Sun: 10:00 AM – 2:00 PM
  • 4.9 ★(38 Google Reviews)
© 2026 MSK Institute. All rights reserved.•Privacy Policy•Terms of Service•Disclaimer•Contact Us

Shikohabad's Leading Computer & Coding Academy

Home
Courses
Live
Material
Truthy & Falsy Values0%
Study Materials
JavaScript for BeginnersProgress 0%
1.1What is JavaScript?1.2How JavaScript Works in Browser1.3Setting up Environment: VSCode, Live Server
4.1Conditional Statements: if, else if, else4.2Switch Statements4.3Truthy & Falsy Values
HomeTutorialsJavaScript for BeginnersTruthy & Falsy Values
For Loop

Truthy & Falsy Values

Beginner12 min read•Updated: 2026-09-15•By Er. Sumit Kumar (MSK Institute)
Study Materials

In JavaScript, every single value has an inherent boolean truth value. When any non-boolean value is evaluated in a boolean context (like an if condition or logical operator), JavaScript automatically coerces it into either true (truthy) or false (falsy).


1. The Falsy Values in JavaScript

Out of the billions of values possible in JavaScript, there are only 8 falsy values. Everything else in the entire language is truthy!

Visual Architecture Blueprint
+-----------------------------------------------------------------------------+
|                      THE 8 FALSY VALUES IN JAVASCRIPT                       |
+-----------------------------------------------------------------------------+
| 1. false                  : The boolean literal false                       |
| 2. 0                      : The number zero                                 |
| 3. -0                     : Negative zero                                   |
| 4. 0n                     : BigInt zero                                     |
| 5. "" (or '' or ``)       : Empty string with zero length                   |
| 6. null                   : The null primitive                              |
| 7. undefined              : The undefined primitive                         |
| 8. NaN                    : "Not a Number" invalid arithmetic result        |
+-----------------------------------------------------------------------------+

If a value is NOT on this exact list of 8, it is 100% TRUTHY!


2. Common Truthy Surprises

Beginners frequently get tripped up by values that seem "empty" or "zero-like" in English, but are completely truthy in JavaScript:

ValueTruthinessWhy is it Truthy?
"0"Truthy!It is a string containing a character (length = 1)
"false"Truthy!It is a non-empty string
" " (whitespace)Truthy!Contains space character (length = 1)
[] (Empty Array)Truthy!All objects and arrays in JS are truthy!
{} (Empty Object)Truthy!All objects in JS are truthy!
function(){}Truthy!Functions are objects, always truthy

The Empty Array Trap:

1const items = [];
2 
3// ❌ BAD: [] is truthy, so this will ALWAYS execute!
4if (items) {
5 console.log("Items exist!"); // Runs even when array is empty!
6}
7 
8// ✅ CORRECT: Check the length!
9if (items.length > 0) {
10 console.log("Items exist!");
11}

3. Explicit Boolean Conversion

You can inspect the truthiness of any value in the console using two methods:

1// Method 1: Boolean() function
2console.log(Boolean("")); // false
3console.log(Boolean("hello"));// true
4console.log(Boolean(0)); // false
5console.log(Boolean([])); // true
6 
7// Method 2: Double NOT (!!) operator
8console.log(!!null); // false
9console.log(!!123); // true

4. Truthy Values in Conditional Logic

1function greetUser(username) {
2 if (username) {
3 console.log(`Welcome back, ${username}!`);
4 } else {
5 console.log("Welcome, Guest!");
6 }
7}
8 
9greetUser("Sumit"); // "Welcome back, Sumit!"
10greetUser(""); // "Welcome, Guest!" (empty string is falsy)
11greetUser(null); // "Welcome, Guest!" (null is falsy)

Interactive Quiz• Knowledge Check

Practice Quiz

Question 1
How many falsy values exist in modern JavaScript?
Question 2
What is the truthiness of an empty array [] in an if condition?
Question 3
What does Boolean("0") evaluate to?
Question 4
Which of the following values is FALSY?
Question 5
How do you safely test whether an array named users actually has elements in it?
Next Lesson

For Loop

Continue learning with hands-on practice, examples, and exercises in the upcoming topic.

Related Lessons

Previous LessonNext Lesson
Switch StatementsFor Loop

Practice Quiz

Test your understanding of this lesson with 5 questions. Each question has one correct answer.

Mentor-Led Practical Training

Master JavaScript for Beginners with Hands-On Projects

Practice in live mentor-led sessions with real projects, mock tests, and verifiable certification at MSK Institute.

View Full CourseBook Free Demo
PreviousNext
PreviousPrevNext