
Truthy and Falsy Values in JavaScript
Truthy and Falsy Values in JavaScript In JavaScript, values used inside a condition are automatically converted into either true or false. This concept is called Truthy and Falsy values. It is very important in conditional statements like if, else, and while. What are Truthy Values? A truthy value is any value that JavaScript treats as true when used inside a condition. Examples of Truthy Values 1 -10 "Hello" "CSK" [] {} true Example Program let team = " CSK " ; if ( team ) { console . log ( " Team exists " ); } Output Team exists Since "CSK" is a non-empty string, JavaScript treats it as true. What are Falsy Values? A falsy value is any value that JavaScript treats as false in a condition. Falsy Values in JavaScript There are only a few falsy values: false 0 "" null undefined NaN Example Program let score = 0 ; if ( score ) { console . log ( " Pass " ); } else { console . log ( " No score " ); } Output No score Since 0 is a falsy value, the else block runs. Simple Example let name = "
Continue reading on Dev.to Tutorial
Opens in a new tab


![[MM’s] Boot Notes — The Day Zero Blueprint — Operations from localhost to production without panic](/_next/image?url=https%3A%2F%2Fcdn-images-1.medium.com%2Fmax%2F1433%2F1*cD3LWDy_XXNTdZ_8GYh6AA.png&w=1200&q=75)

