No video

NaN and isNaN in JavaScript

  Рет қаралды 13,348

Steve Griffith - Prof3ssorSt3v3

Steve Griffith - Prof3ssorSt3v3

Күн бұрын

The global property NaN represents any value that is Not A Number.
The global isNaN method allows you to check whether or not any value is Not A Number. The key point about using the isNaN( ) method is understanding that everything it tests is converted to a Number before the test is actually run.
Code GIST: gist.github.co...

Пікірлер: 35
@MarstonH
@MarstonH 7 ай бұрын
your calm, clarity, and experience is much appreciated
@tranquiloteov
@tranquiloteov 3 жыл бұрын
You just saved me from a brain neurism. I've been reading the Mozilla documentation for half an hour and I didn't understand why it gave "false" with null or true. You explain great, I hope you make more videos. Thanks a lot.
@salvadorgonzales5470
@salvadorgonzales5470 6 жыл бұрын
Really enjoy your videos, your teaching style is just amazing.
@SteveGriffith-Prof3ssorSt3v3
@SteveGriffith-Prof3ssorSt3v3 6 жыл бұрын
Fuey Won Thanks!
@Aprajita-mc8uy
@Aprajita-mc8uy 9 ай бұрын
Thanks a lot. It really helped me as I was confused between Number.isNaN and isNan function.
@rotrose7531
@rotrose7531 4 жыл бұрын
Thank you very much, I hope someday my JS will get a little bit near the level you have mastered. I often get impressed by how many work you have done behind the scenes. Thank you.
@williammansfield7471
@williammansfield7471 3 жыл бұрын
Gratitude. Saved me hours of agony.
@dmytromoroz4451
@dmytromoroz4451 4 жыл бұрын
Splendid overview. Thanks a lot!
@therealkayode
@therealkayode 2 жыл бұрын
Thank you. I am very grateful.
@bsherrh4916
@bsherrh4916 5 жыл бұрын
Thank you, it was very useful
@arzu300
@arzu300 2 жыл бұрын
Thank you, now it all makes sense to me
@chesterxp508
@chesterxp508 3 жыл бұрын
Another very cool tutorial !!!
@vrutishah3442
@vrutishah3442 5 ай бұрын
Why does isNaN(" ") Returns false value? What is the logic behind the strings returning into false value?
@SteveGriffith-Prof3ssorSt3v3
@SteveGriffith-Prof3ssorSt3v3 5 ай бұрын
It first tries to do a conversion of the value being passed in from whatever to number. If the conversion worked then it asks if that value is not a number. isNaN(" ") - false because Number(" ") == 0 which is a number isNaN("") - false because Number("") == 0 which is a number isNaN("hello") - true because Number("hello") == NaN ...
@fivekncklshufl6146
@fivekncklshufl6146 3 жыл бұрын
how would I check if an existing variable is equal to NaN?
@alisabah9088
@alisabah9088 Жыл бұрын
thank u \
@romeojoseph766
@romeojoseph766 Жыл бұрын
what is the right way to check whether a value is a number data type or any other(without using regex)?
@SteveGriffith-Prof3ssorSt3v3
@SteveGriffith-Prof3ssorSt3v3 Жыл бұрын
If you want to know if a value is a primitive value of type number, use the typeof operator
@romeojoseph766
@romeojoseph766 Жыл бұрын
@@SteveGriffith-Prof3ssorSt3v3 thanks for the information again!
@yarik83men51
@yarik83men51 4 жыл бұрын
Thx
@rameshbhaip4732
@rameshbhaip4732 5 жыл бұрын
Can anyone explain this console.log(Number('hello')) // returns NaN console.log(Number.isNaN("hello")); // returns false
@SteveGriffith-Prof3ssorSt3v3
@SteveGriffith-Prof3ssorSt3v3 5 жыл бұрын
Number( ) - is taking a string value and trying to create a number from it. If the string cannot be interpreted as a number then the resulting value will be NaN (Not A Number). The isNaN( ) method takes a string and tests to see if the string is Not A Number.
@rameshbhaip4732
@rameshbhaip4732 5 жыл бұрын
@@SteveGriffith-Prof3ssorSt3v3 then Number.isNaN("hello") should return true
@SteveGriffith-Prof3ssorSt3v3
@SteveGriffith-Prof3ssorSt3v3 5 жыл бұрын
@@rameshbhaip4732 yes
@rameshbhaip4732
@rameshbhaip4732 5 жыл бұрын
@@SteveGriffith-Prof3ssorSt3v3 but it is returns false instead of true
@JS-zm5se
@JS-zm5se 3 жыл бұрын
what will be output of IsNaN(NaN) and why?
@SteveGriffith-Prof3ssorSt3v3
@SteveGriffith-Prof3ssorSt3v3 3 жыл бұрын
The result would be true. isNaN( ) checks if the provided value is Not A Number. If you give it NaN, then it is, by definition, Not A Number. So, isNaN( ) will return true because NaN is not a number.
@JS-zm5se
@JS-zm5se 3 жыл бұрын
@@SteveGriffith-Prof3ssorSt3v3 thank you
@Thehealthycornerstore
@Thehealthycornerstore 6 жыл бұрын
Do you know how to fix this when it appears in an ecommerce store? I'm at a loss, and I'm definitely not a programmer :/
@SteveGriffith-Prof3ssorSt3v3
@SteveGriffith-Prof3ssorSt3v3 6 жыл бұрын
Fix what? If there is a problem on your e-commerce store then you probably need a programmer to fix it.
@Thehealthycornerstore
@Thehealthycornerstore 6 жыл бұрын
Thanks, captain o.
@SteveGriffith-Prof3ssorSt3v3
@SteveGriffith-Prof3ssorSt3v3 6 жыл бұрын
I mean if it has to do with money, don't mess around with it. Hire a programmer who knows what they are doing.
@kunjchoksi
@kunjchoksi 6 жыл бұрын
"let h" returns false!
@SteveGriffith-Prof3ssorSt3v3
@SteveGriffith-Prof3ssorSt3v3 6 жыл бұрын
Good catch. Yes. new Date() returns an integer timestamp... therefore false. Had I not been trying to finish the video quickly and had console logged out h then I would have corrected that. I have updated the code GIST with comments.
@kunjchoksi
@kunjchoksi 6 жыл бұрын
thats fine :p
Understanding the Keyword THIS in JavaScript
13:59
Steve Griffith - Prof3ssorSt3v3
Рет қаралды 9 М.
Logical Short-Circuiting in JavaScript
9:51
Steve Griffith - Prof3ssorSt3v3
Рет қаралды 6 М.
هذه الحلوى قد تقتلني 😱🍬
00:22
Cool Tool SHORTS Arabic
Рет қаралды 90 МЛН
Angry Sigma Dog 🤣🤣 Aayush #momson #memes #funny #comedy
00:16
ASquare Crew
Рет қаралды 46 МЛН
What is the Difference between encodeURI and encodeURIComponent
10:41
Steve Griffith - Prof3ssorSt3v3
Рет қаралды 10 М.
ES5 Custom Object Methods, Getters, and Setters
9:49
Steve Griffith - Prof3ssorSt3v3
Рет қаралды 12 М.
JavaScript Tutorial For Beginners - NaN (Not a Number)
6:35
Net Ninja
Рет қаралды 87 М.
#31 Email Validation in JavaScript
17:09
Telusko
Рет қаралды 142 М.
WTF Is JavaScript Variable Hoisting
8:50
Colt Steele
Рет қаралды 27 М.
JavaScript Function Currying
11:41
Steve Griffith - Prof3ssorSt3v3
Рет қаралды 15 М.
Reference Vs Value In JavaScript
15:12
Web Dev Simplified
Рет қаралды 182 М.
ParseInt Method JavaScript
6:57
Chart JS
Рет қаралды 10 М.