javascript / beginner
Snippet
Truthy and Falsy Values
JavaScript evaluates non-boolean values as 'truthy' or 'falsy' in conditions. An empty string is always considered falsy.
snippet.js
javascript
1
2
3
4
const username = "";if (!username) {console.log("No name provided");}
nodejs
Breakdown
1
const username = "";
Initializes a variable with an empty string.
2
if (!username)
The '!' operator flips the falsy empty string to true, triggering the block.