JS Tricks

The typeof operator

By xyz on 2 weeks ago|0 comment||
0

The typeof operator is used in JavaScript to determine the type of a given value. However, it can sometimes return unexpected results, leading to the following joke:

Why did the JavaScript developer go broke?
Because he used typeof on a penny and got a "string" instead of a "number."

let pennyAsNumber = 0.01;
let pennyAsString = "0.01";

// Use typeof to check the types
console.log(typeof pennyAsNumber);  // Output: "number"
console.log(typeof pennyAsString);  // Output: "string"

// Example of an unexpected typeof result
let nullValue = null;
console.log(typeof nullValue);  // Output: "object"

Add a Comment

Comments

Comments MIA, jokes needed ASAP. Add yours! 😄

What is JavaScript Hacks? 🚀

Hey there, fellow code adventurer! Ever wished JavaScript could be more than just lines of serious code? Well, welcome to JS Hacks – where JavaScript gets a playful makeover! 🎉

So, whether you're a coding newbie or a seasoned pro, join us on this epic quest to discover the quirkiest, coolest, and downright silliest JavaScript hacks out there. Trust us, your code will thank you (and maybe even crack a smile). 😄

Ready to hack, slash, and LOL your way through JavaScript? Let's dive in and unleash the fun-tastic power of JS Hacks together! 💻✨


DISCOVER

ENGAGE

Add Trick