JS Type Casting, Converting, and Coercion

  Рет қаралды 3,275

Steve Griffith - Prof3ssorSt3v3

Steve Griffith - Prof3ssorSt3v3

Күн бұрын

Пікірлер: 26
@LR-bc8js
@LR-bc8js Жыл бұрын
My favorite teacher on KZbin!!
@aakashsingh604
@aakashsingh604 4 жыл бұрын
I have learned a lot by coming to your channel. Thanks a lot for it!
@chesterxp508
@chesterxp508 2 жыл бұрын
Another very cool tutorial!
@serhii113
@serhii113 4 жыл бұрын
Thanks! A couple of nuances ;) +{} // NaN +[1] // 1 +[1,2] // NaN "If an object has no primitive value, valueOf returns the object itself." (c) MDN
@SteveGriffith-Prof3ssorSt3v3
@SteveGriffith-Prof3ssorSt3v3 4 жыл бұрын
I've updated my code Gist to reflect the two Array differences for +[1] and +[1,2]. The Arrays get turned into the Primitive string values "1" and "1,2" before being converted to Numbers which is why we get the 1 and NaN results. Not sure why I had 0 written for the Objects. They will always be NaN. Thanks for pointing it out.
@rmnkot
@rmnkot 4 жыл бұрын
Very important core knowledge! Thanks, as always!
@SteveGriffith-Prof3ssorSt3v3
@SteveGriffith-Prof3ssorSt3v3 4 жыл бұрын
My pleasure!
@Robert-cw9ev
@Robert-cw9ev 4 жыл бұрын
Thanks for video! I've also looked at other explanations on internet and I found out that: - "" to number is 0; - [] to number is 0, because it first converts to string which is "", then it converts "" to number which is 0; - "" == 0 its true. So equals operator converts both to number, which means that "" to number is 0.
@BrendanMetcalfe
@BrendanMetcalfe 4 жыл бұрын
Looks like you put in a lot of work on this! Good work man
@katherineprokofieva5707
@katherineprokofieva5707 3 жыл бұрын
thanks for your video!
@joaovaz3473
@joaovaz3473 4 жыл бұрын
Great video, always! A question: isn't an empty array a falsy value?
@SteveGriffith-Prof3ssorSt3v3
@SteveGriffith-Prof3ssorSt3v3 4 жыл бұрын
Nope. Everything that is not falsy is truthy in JS. The falsy values are: false, 0, "", null, undefined, and NaN. Arrays are Objects. They are not on the list, so they are truthy. Run this: if( [ ] ){ console.log('array is truthy'); } However, think about this - Convert an empty Array to a String and you get "". Convert that into a Boolean and you get false.
@joaovaz3473
@joaovaz3473 4 жыл бұрын
@@SteveGriffith-Prof3ssorSt3v3 Ahh, ok. Thanks!
@tracyadams6787
@tracyadams6787 4 жыл бұрын
Great video. Any chance you could post the link to the operator precedence reference?
@SteveGriffith-Prof3ssorSt3v3
@SteveGriffith-Prof3ssorSt3v3 4 жыл бұрын
It is in the code gist linked to in the description
@webb-developer
@webb-developer 11 ай бұрын
@siddharthapothan5165
@siddharthapothan5165 3 жыл бұрын
Your videos are really helpfull, learnt a lot. But is Number({}) value 0? Thanks!!!
@SteveGriffith-Prof3ssorSt3v3
@SteveGriffith-Prof3ssorSt3v3 3 жыл бұрын
That was a copy paste error in my comments. The gist was updated to show that converting an empty object to a number gives you NaN.
@guignolguignol5340
@guignolguignol5340 4 жыл бұрын
is there in ASP classic or javascript function like CURL in PHP
@SteveGriffith-Prof3ssorSt3v3
@SteveGriffith-Prof3ssorSt3v3 4 жыл бұрын
fetch( ) is the modern JavaScript method for making HTTP Requests. XMLHttpRequest is the old JS method for making HTTP Requests.
@guignolguignol5340
@guignolguignol5340 4 жыл бұрын
@@SteveGriffith-Prof3ssorSt3v3 Thank you, Mr. Steve, in your view, what you will use to do better
@jassihambran
@jassihambran 4 жыл бұрын
hey steve. Could you help us in how to setup terminal to run javascript files without any extension?Thanks in advance
@aarong9327
@aarong9327 4 жыл бұрын
Type node in your terminal and it'll run the code in that file.
@jassihambran
@jassihambran 4 жыл бұрын
@@aarong9327 it does not. When i try it says file could not be found.
@SteveGriffith-Prof3ssorSt3v3
@SteveGriffith-Prof3ssorSt3v3 4 жыл бұрын
It does on Linux and MacOS. I haven't tried on Windows.
@NairiKhachatryan
@NairiKhachatryan Ай бұрын
let emptyStr = '' Number(emptyStr) // 0
JS Code Structure Moving Beyond Beginner
21:31
Steve Griffith - Prof3ssorSt3v3
Рет қаралды 14 М.
У вас там какие таланты ?😂
00:19
Карина Хафизова
Рет қаралды 22 МЛН
They Chose Kindness Over Abuse in Their Team #shorts
00:20
I migliori trucchetti di Fabiosa
Рет қаралды 11 МЛН
All Rust string types explained
22:13
Let's Get Rusty
Рет қаралды 181 М.
Deep Dive into Array from method
22:05
Steve Griffith - Prof3ssorSt3v3
Рет қаралды 2,8 М.
Watch This If You Don’t Understand Type Coercion
8:19
Web Dev Simplified
Рет қаралды 129 М.
Object-Oriented Programming is Embarrassing: 4 Short Examples
28:03
Brian Will
Рет қаралды 2,1 МЛН
The Difference between JS Expressions and Statements
8:45
Steve Griffith - Prof3ssorSt3v3
Рет қаралды 7 М.
PROOF JavaScript is a Multi-Threaded language
8:21
Beyond Fireship
Рет қаралды 287 М.
Important differences between textContent and innerText
11:44
Steve Griffith - Prof3ssorSt3v3
Рет қаралды 2,5 М.
Coercion and Type Conversion in JavaScript, Simplified
10:05
Deeecode The Web
Рет қаралды 999
How to Learn to Code FAST (Do This or Keep Struggling)
11:00
Andy Sterkowitz
Рет қаралды 715 М.