The Weird Parts of JavaScript

  Рет қаралды 53,285

Colt Steele

Colt Steele

Күн бұрын

In this video we cover some of the oddest, most unexpected behavior in JavaScript. We'll read the spec, dive deep into how floating point numbers are stored, and take apart the abstract equality operator.
- Video Notes: www.notion.so/Weird-Parts-of-...
- WTFJS Repo: github.com/denysdovhan/wtfjs
- You Don't Know JS Repo: github.com/getify/You-Dont-Kn...
If you're ready to launch your career as a software engineer, check out my job-guaranteed bootcamp with Springboard: springboard.com/workshops/sof...

Пікірлер: 110
@yuhceeofficial
@yuhceeofficial 4 жыл бұрын
I am glad you have posted a video. I have really missed you.
@sexyeur
@sexyeur 4 жыл бұрын
Highly informative. Thank you!
@Nicoarielpkr
@Nicoarielpkr 4 жыл бұрын
I know nothing about him, but i'm just being nice, had me spitting my coffe :P
@karangirigauswami
@karangirigauswami 4 жыл бұрын
😂
@mverma7845
@mverma7845 2 жыл бұрын
yeah Colt is a funny guy....
@Luxcium
@Luxcium 4 жыл бұрын
Thank for your amazing and passionate work this kind of topic is truly interesting... I am wondering if you plan on doing something about back end like NodeJS one day soon
@ColtSteeleCode
@ColtSteeleCode 4 жыл бұрын
Working on some Node content for a new course right now. I'm happy to make KZbin videos on it, but it's kind of a large topic so I need suggestions about what in particular to cover!
@Luxcium
@Luxcium 4 жыл бұрын
Colt Steele please 🙏 please 🥺 don’t do like in the 75 Udemy Intro course I have purchased... if you do something NODEJS on your KZbin channel it’s *not* required to be web server stuff again (NodeJs can do way more) please teach us what we can’t get from those tutorials... explain us the real stuff: (streams, piping, buffers, sockets and +CHILD PROCESSES+) all that great stuff we all need a library to do and that we can’t quite understand after all beginners tutorials ... NodeJs is amazing and the tutorials don’t explain how it works inside (except for the existence of the event loop) ...
@surjagain
@surjagain 4 жыл бұрын
Got a headache now :) Thanks for the fun video :)
@BrokoIis
@BrokoIis 4 жыл бұрын
I thought I knew most of the weird things of JS, but this video just showed that there's more!
@ennakrbouchaib9139
@ennakrbouchaib9139 4 жыл бұрын
Any function well be work with a number, just make two points. like this : 10..toFixed(x) because the first point is not to reference, for the dozens, like 10.2 or 10.1
@keemeshrampersad8859
@keemeshrampersad8859 4 жыл бұрын
Love your work Colt...
@AJQuickShow
@AJQuickShow 4 жыл бұрын
Hello bro i recently brought your web development boot camp course it was awesome 👍 Thx for your effort
@intisark587
@intisark587 4 жыл бұрын
Hi,colt can you do a vidio on css grid,would be really helpful
@harshpatel7704
@harshpatel7704 4 жыл бұрын
I think it might help others. This same method describes the areay problem in video too!
@GleamGoldenrock
@GleamGoldenrock 4 жыл бұрын
Great video!
@danielzaiser
@danielzaiser 4 жыл бұрын
12:20 you said it represents infinity if it has all zeroes, but it's actually ones, and it says so right there on screen as well
@AAA-bo1uo
@AAA-bo1uo 4 жыл бұрын
Lol.. supervisor chose JS (node) for our project because it's event driven and non I/O blocking, then proceeded to tell us to explicitly use it in a sync manner whilst using external libraries... imagine trying to use an environment and eco system based on async in a synchronized manner.. it's crazy.
@aliemadzadeh9293
@aliemadzadeh9293 4 жыл бұрын
thanks:) it was fun. I did not know
@Hyp3rSp8c3
@Hyp3rSp8c3 4 жыл бұрын
Ay.. yay, yay! This is the source of my headache. :-)
@solesolver5740
@solesolver5740 4 жыл бұрын
Which browser theme do you use?
@TyDurr1
@TyDurr1 4 жыл бұрын
I can at least speak to NaN !== NaN. Essentially, it is _intended_ to make your code fail fast and hard, so that you know as soon as possible during execution that some calculation you did gave you a number that wasn’t a number. On top of that, all operations where an operand is NaN will result in NaN as well, and all comparisons against NaN return false, again in an attempt to protect you from utilizing that value somewhere where it could break something.
@jadedansk5631
@jadedansk5631 4 жыл бұрын
3:30, I believe this is cause putting a ‘.’ by a int literal makes js think you’re trying to make a float
@martinkrisell7953
@martinkrisell7953 4 жыл бұрын
Great video! However the problem with a newline after the return keyword is unaffected by the recommendation to "always use semicolons". Even if you write your semicolons, undefined will be returned. The only way to avoid it is to learn to not put return on its own line, and that has nothing to do with semicolons.
@madmanX1314
@madmanX1314 4 жыл бұрын
Martin Krisell Yes. That is being confused so often
@sobanya_228
@sobanya_228 4 жыл бұрын
It's much easier to learn rules of omitting semicolons and make prettier format it in a way you need automagicaly (either with or without, depending on the standard you use)
@khattami240193
@khattami240193 2 жыл бұрын
i omit semicolon in all my codebase, for the sake of readability
@micoberss5579
@micoberss5579 4 жыл бұрын
Javascript is all weird
@ismaelgoldsteck5974
@ismaelgoldsteck5974 4 жыл бұрын
1.toFixed(1) is not unexcpected since js wants a floating point number. Just write 1..toFixed(1)
@fluffyfetlocks
@fluffyfetlocks 4 жыл бұрын
Isn't === just.. It has to be the same data type where as == it can compare different data types
@omnijack
@omnijack 4 жыл бұрын
Ben Mitchell === checks for the same object in memory. Primitives, like the number 1 or the letter a, share the same location. But {} === {} should be false because each {} is a new object literal.
@rachada2532
@rachada2532 4 жыл бұрын
Redux please ❤️
@harshpatel7704
@harshpatel7704 4 жыл бұрын
Javascript just evaluates an object with value as true. Like an areay with one element. While empty string or array as false as it does not have any method. Thats why we check that string has value by just sending string as a argument to if statement.
@doublex85
@doublex85 4 жыл бұрын
35..toFixed(1)
@yuhceeofficial
@yuhceeofficial 4 жыл бұрын
Do a video explaining how javascript runs its program, closures and the event loop. That is, what actually happens behind the scenes when you run your code. Thanks
@williamdrum9899
@williamdrum9899 2 жыл бұрын
I didn't even know javascript had a double equals lol. I've never used it but I have seen what the code looks like
@puppy0cam
@puppy0cam 4 жыл бұрын
The only time I use == is to treat null and undefined as the same thing.
@omnijack
@omnijack 4 жыл бұрын
There are situations where null and undefined behave very differently, so learn to use === and always check for exact values.
@puppy0cam
@puppy0cam 4 жыл бұрын
@@omnijack in my use cases I don't need to use the value, I just need to know that it doesn't care about the value.
@Luxcium
@Luxcium 4 жыл бұрын
You are using != undefined to check both (instead of !==) but == undefined is not the same thing (I am usually using != undefined to test it’s not undefined or not null but I don’t use == undefined)
@SentimentalMo
@SentimentalMo 4 жыл бұрын
JavaScript designers: “hmmm, how can we break the rule of least astonishment……as much as possible? Let start by making true == false‼️”
@ETTechs
@ETTechs 2 жыл бұрын
typeof NaN returns 'number'
@MaxPicAxe
@MaxPicAxe 4 жыл бұрын
I am truly against this automatic semi-colon insertion. Ok, some may consider it convenient. But it prevents many ways of formatting your code. I always like to put my braces on new lines but there are many situations where this can't be done in JS like you showed with the return statement.
@circuit10
@circuit10 4 жыл бұрын
I don't agree- I always forget them. Maybe it should be optional.
@CathrineMacNiel
@CathrineMacNiel 4 жыл бұрын
That's the reason why every language ever has a coding guideline that you (in JavaScript) enforce with eslint.
@Luxcium
@Luxcium 4 жыл бұрын
Ok so 123..toFixed(2) is ok ...
@DanielSouza-nq1hw
@DanielSouza-nq1hw 4 жыл бұрын
Shit that hurts my brain
@zotac1018
@zotac1018 4 жыл бұрын
What ide are you using here?
@abeplus7352
@abeplus7352 4 жыл бұрын
He's using chrome lol .
@dima6488
@dima6488 4 жыл бұрын
Give me Redux or give me death!
@kamran6998
@kamran6998 4 жыл бұрын
hi colt.. is there anyway that we could contact you? like by email or anything else? I need some advice from a professional programmer???
@Reellron
@Reellron 4 жыл бұрын
The following statements are oddly false as well: 0.1 + 0.2 == 0.3 10.495 + 4.8 == 15.295 10.495 + 34.8 == 45.295 The following statement is true, which screwed my application up today, until I found it out and rounded it off. 10.495 + 34.8 == 45.294999999999995 The numbers on the left hand side were compared to a value in MS SQL DB table, which was 45.295..
@williamdrum9899
@williamdrum9899 2 жыл бұрын
That's not a Javascript issue, it's an inherent flaw in IEEE 754 floating point representations.
@Reellron
@Reellron 2 жыл бұрын
​@@williamdrum9899, whether it's a javascript issue or not is more of a philosifical argument. It's an issue that exists in JavaScript, that it's inherited is not as important.
@williamdrum9899
@williamdrum9899 2 жыл бұрын
@@Reellron By that I meant that almost every programming language is like this, floating point and binary just don't work together well. You're trying to represent something that can potentially be infinitely long so you can only get a ballpark estimate. What I don't get, however, is why the computer can't understand that the answer to an addition problem can't have more significant digits than the operands and round off based on that
@prateeksingh6757
@prateeksingh6757 4 жыл бұрын
Why no one have good JavaScript ES6 course on udemy.
@ColtSteeleCode
@ColtSteeleCode 4 жыл бұрын
I just finished recording my new es2015/es6 course last night! Now I have to do all the editing, but the course is completely recorded.
@prateeksingh6757
@prateeksingh6757 4 жыл бұрын
@@ColtSteeleCode I will join the course on udemy.
@sabikksabikk6156
@sabikksabikk6156 4 жыл бұрын
Waiting for course, your explains is greate
@Luxcium
@Luxcium 4 жыл бұрын
Colt Steele will you do ES7, ES8, ES9, ES10 LoL ... also will I get a bigger discount if I already know JavaScript but I like the way you teach and want to follow along or can you hack me a bootlegger version LoL 😂
@dtellei
@dtellei 4 жыл бұрын
i-triple-e? :)
@RiccardoMazzia
@RiccardoMazzia 4 жыл бұрын
JavaScript is like the honey badger... Soo nasty! ;)
@ilking467
@ilking467 4 жыл бұрын
Noh. Like a skunk
@yuhceeofficial
@yuhceeofficial 4 жыл бұрын
You didn't update us on how your chicks pets are doing?
@ColtSteeleCode
@ColtSteeleCode 4 жыл бұрын
I will in the next video, I promise! I was going to include some video of them today, but the room they are in right now is very messy and I didn't want people to see that :) They are growing so fast, it's amazing to see.
@yuhceeofficial
@yuhceeofficial 4 жыл бұрын
@@ColtSteeleCode Aww... That's so cute. But it's kinda funny that they are enjoying this care now to only to end up in your belly someday...😂
@puesnovay
@puesnovay 4 жыл бұрын
@@yuhceeofficial what!?
@Luxcium
@Luxcium 4 жыл бұрын
Egbo Uchenna Matthew 😮 he will not only eat the eggs 🍳? I don’t think he would be able to eat them he will be like their father (but if it’s a rooster 🐓 he will have to eat it instead of it’s eggs... eating exclusively roosters eggs is dangerous and caused many to die of starvation)
@cintron3d
@cintron3d 4 жыл бұрын
Great video, but I disagree on the semicolons bit. I prefer to just not use semicolons and write functions like this `const myFunc = () => { ... }`
@circuit10
@circuit10 4 жыл бұрын
Is that a joke?
@ahmadganteng7435
@ahmadganteng7435 4 жыл бұрын
Hi.. I am a javaneese.. FYI, this complexity is just way too little compared to the real java language (a.k.a boso Jowo).. Lol
@Cognitoman
@Cognitoman 4 жыл бұрын
Javascript isn’t weird....php is weird lol I promise
@rikipebrianto560
@rikipebrianto560 4 жыл бұрын
awokwokwok
@Luxcium
@Luxcium 4 жыл бұрын
Promise ? Or asynk await LoL 😝
@lucasfelipe-ze5sy
@lucasfelipe-ze5sy 4 жыл бұрын
javascript == weird // true javascript == javascript // false
@TheMessixaviniesta
@TheMessixaviniesta 4 жыл бұрын
Javascript is a mess
@CathrineMacNiel
@CathrineMacNiel 4 жыл бұрын
It's a beautiful mess
@SuperemeRed
@SuperemeRed 4 жыл бұрын
I will NOT put semicolons in my private code, it's ugly and tedious to write. As far as I know you only need to add a semicolon on a new line when it starts with a round or square bracket. ;(...) // like this.
@nicholasmaniccia1005
@nicholasmaniccia1005 4 жыл бұрын
Not ugly use a linter, and if that's tedious idk man that says more about you
@SuperemeRed
@SuperemeRed 4 жыл бұрын
@@nicholasmaniccia1005 Haha I'm fine with being lazy in my private code ^^ BTW how is a linter going to help me hide those ugly semicolons? I don't like them visually, they clutter up readability.
@salembeats
@salembeats 4 жыл бұрын
@@SuperemeRed A semicolon denotes the end of a statement, just like a period denotes the end of a sentence. Are you gong to stop typing periods at the ends of your sentences as well?
@SuperemeRed
@SuperemeRed 4 жыл бұрын
@@salembeats I know this, also as mentioned in the video, JS auto adds semicolons for you, this is a topic that has been discussed many times before in videos, articles and forums, and the conclusion is that there really is not a problem with omitting the semicolon (statement ender) as it will be auto inserted any way, the only scenario that will break is when you begin a new line with ( or [ and all you have to do is begin the line with ; in-front like this ;( and all is well. But of course, follow the code convention when you are collaborating with others. The point is that it's like, why manually add a period when the editor will automatically add it for you. And while I get you, the period and semicolon isn't a perfect 1 to 1 comparison in the way the statement or sentence is terminated due to new line and brackets and so on.
@SuperemeRed
@SuperemeRed 4 жыл бұрын
@@nicholasmaniccia1005 Here is a great video explaining the reasoning for omitting semicolons: kzbin.info/www/bejne/h53VXnl9l81-l6s
@Steve-Richter
@Steve-Richter 4 жыл бұрын
I have never had to use ===.
@Luxcium
@Luxcium 4 жыл бұрын
Zahra Q my friend which was working on construction 🏗 sites never needed a harness and now he’s dead 💀 LoL 😂
@christianthompson1839
@christianthompson1839 4 жыл бұрын
Solution: don't use JavaScript
@isaque1764
@isaque1764 3 жыл бұрын
yeah, use C for developing the website front-end
@christianthompson1839
@christianthompson1839 3 жыл бұрын
@@isaque1764 exactly ❤
@jsonkody
@jsonkody 4 жыл бұрын
W8 what??? That semicolons section: "and thats why you should ...". No! If you know what you doing you should ommit these stupid semicolons.
@jsonkody
@jsonkody 4 жыл бұрын
Also that return situation where it matters cannot be save d by typing semicolon. You just need to start onject on same line so whats the point in typing semicolons everywhere?
@avibank
@avibank 4 жыл бұрын
Javascript is a vulgar language.
@Luxcium
@Luxcium 4 жыл бұрын
avi bank I am in love with JavaScript and his curse 🦹🏼‍♂️ If you prefer well behaved people then you should probably date JS little sister TypeScript she is an angel 😇
@mortyjr2334
@mortyjr2334 4 жыл бұрын
Everything is weird in JavaScript, in my opinion it's one of the worst languages out there.
@CathrineMacNiel
@CathrineMacNiel 4 жыл бұрын
Ever used PHP?
@mortyjr2334
@mortyjr2334 4 жыл бұрын
@@CathrineMacNiel PHP is easier than JavaScript imo.
JS Arrow Functions: Everything You Need to Know
20:23
Colt Steele
Рет қаралды 31 М.
JS Spread Operator: How It Works & Why I Love It
16:31
Colt Steele
Рет қаралды 75 М.
Купили айфон для собачки #shorts #iribaby
00:31
Just try to use a cool gadget 😍
00:33
123 GO! SHORTS
Рет қаралды 73 МЛН
Её Старший Брат Настоящий Джентельмен ❤️
00:18
Глеб Рандалайнен
Рет қаралды 8 МЛН
ИРИНА КАЙРАТОВНА - АЙДАХАР (БЕКА) [MV]
02:51
ГОСТ ENTERTAINMENT
Рет қаралды 1,5 МЛН
JavaScript the Hard Parts: Closure, Scope & Execution Context
57:05
The Weird History of JavaScript
12:09
Fireship
Рет қаралды 1,2 МЛН
Why You Should Be Using CSS Variables
13:28
Colt Steele
Рет қаралды 27 М.
The JavaScript Survival Guide
14:47
Fireship
Рет қаралды 716 М.
JavaScript Is Weird (EXTREME EDITION)
21:29
Low Byte Productions
Рет қаралды 682 М.
The Only 2 CSS Properties You Should Animate *
15:21
Colt Steele
Рет қаралды 65 М.
CONCURRENCY IS NOT WHAT YOU THINK
16:59
Core Dumped
Рет қаралды 86 М.
Looking Under the Hood of JavaScript
6:34
ThePrimeagen
Рет қаралды 176 М.
Настоящий детектор , который нужен каждому!
0:16
Ender Пересказы
Рет қаралды 396 М.
сюрприз
1:00
Capex0
Рет қаралды 1,3 МЛН
Хотела заскамить на Айфон!😱📱(@gertieinar)
0:21
Взрывная История
Рет қаралды 2,2 МЛН