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! 😄