JavaScript types: Number.isFinite() vs Number.isInteger()

✨ Today’s tiny JavaScript “aha!” moment While solving a small coding problem, I went down a fun little rabbit hole about how JavaScript handles types. 😄 I’d honestly never paid much attention to the difference between Number.isFinite() and Number.isInteger() before! At first, they sounded like they’d do pretty much the same thing - but nope! Here’s what I learned (and wish I’d realized sooner): 💡 Number.isFinite() Checks if a value is a finite number (not Infinity, -Infinity, or NaN, etc.). It also doesn’t convert strings - so "5" is not considered finite. Number.isFinite(5); // true Number.isFinite(Infinity); // false Number.isFinite('5'); // false 💡 Number.isInteger() Checks if a value is a whole number (integer). So 3.14, or '10,' will fail here too. Number.isInteger(10); // true Number.isInteger(3.14); // false Number.isInteger('10'); // false And just to make things spicy: There’s also the old global isFinite() (which does convert strings to numbers): isFinite('10'); // true Number.isFinite('10'); // false It’s such a tiny detail, but I love how JavaScript keeps reminding me that the “simple” things often hide the best lessons. Every bug or small confusion ends up teaching me something new. 💻✨ Takeaway: Know when JavaScript is being strict (Number.isFinite) and when it’s being “helpful” by converting things behind the scenes (isFinite). #JavaScript #LearningByDoing #CodingJourney #WebDevelopment #DeveloperNotes

Beautifully said! I completely relate — those tiny details always often carry the biggest lessons. Every little bug or confusion truly helps us grow as developers. 💡

To view or add a comment, sign in

Explore content categories