In JavaScript, Truthy expressions evaluate to boolean true value and Falsy expressions evaluate to boolean false value. Unlike other programming languages, truthy and falsy values are not limited to boolean data types and comparisons. They can have many other forms. Let us learn what makes an expression truthy …
testTruthy(newBoolean(false)); // truthy (object is always true)
testTruthy(''); // falsy
testTruthy('Packt'); // truthy
testTruthy(newString('')); // true (object is always true)
testTruthy(1); // truthy
testTruthy(-1); // truthy
testTruthy(NaN); // falsy
testTruthy(newNumber(NaN)); // truthy (object is always true)
testTruthy({}); // truthy (object is always true)
varobj = { name: 'John'};
testTruthy(obj); // truthy
testTruthy(obj.name); // truthy
Happy Learning !!
Comments
Subscribe
3 Comments
Most Voted
NewestOldest
Inline Feedbacks
View all comments
Lokesh Gupta
A fun-loving family man, passionate about computers and problem-solving, with over 15 years of experience in Java and related technologies.
An avid Sci-Fi movie enthusiast and a fan of Christopher Nolan and Quentin Tarantino.
Comments