Empty array is evaluated the same way as empty object in js - it just substitutes the object/array with reference to heap (like 0xFFFFFFFFFFFF) which is true. But Number([]) is super weird and makes no sense. Well, this code makes no sense, so why the result should make sense...
I see 1 good use case for String.raw: defining a string variable containing backslashes. For example, windows filepath. String.raw`D:\path\to\file`, which is more readable than "D:\\path\\to\\file". This can be applicable to any string value containing backslashes which you don't want to escape everytime. It can be even inlined SQL script which can contain string literals (not a good idea, but anyway)
personally was thinking with regex, if you needed to use the constructor (for whatever reason), which takes the representation of the regex *as a string*, in which you would have to double-escape any special chars (e.g. \d -> "\\d"). This would not be necessary using String.raw.
10:18 I haven’t heard of String.raw in JS but there is a similar feature in Dart. One use case for them is declaring regular expression string literals. You don’t have to deal with escaping certain characters etc.
I recently used a version of String.raw in C# where instead you use the @ symbol before the string (string myString = @"my string contains "quotes" and stuff"), and this was for adding a SQL Server connection string to my app, so instead of using \ before the " to consider it part of the string itself, you use the raw value of the string which is everything contained within the outermost quotes
It’s an issue that can only happen in a dynamic language because it has to do some kind of type “guessing” since your types are not explicitly defined. I’m learning Elixir right now and I also don’t like the “ambiguity” of type sometimes - like having a list of mixed types. So it’s not just JS (although JS could be the worst offender). That said, I still use JS and Python and as mentioned I’m learning Elixir - another dynamic language so no need to get defensive 😉
For the floating point precision problem: Does JavaScript give you standard library tools to deal with errors in floats? I'm just wondering because in other languages, like Rust or C, you can just cast 0.1 and 0.2 as f32 (Rust) or float (C) which then is equal to 0.3, so 0.1 + 0.2 == 0.3 is true when cast as f32. Rust: println!("{}", 0.1 as f32 + 0.2 as f32 == 0.3 as f32); Even other interpreted languages like Python give you the 'decimal' module as part of the standard library, which lets you handle it like so: Python: from decimal import Decimal print(Decimal('0.1') + Decimal('0.2') == Decimal('0.3')) which returns true. The Decimal module handles decimal numbers as exactly their mathematical equivalent (up to a certain cutoff, which can be manually extended).
the rust thing is really weird but surprisingly true though I don't think it's comparable to the decimal lib in python it's just that JS floats are 64 bit by default, and you're manually casting it to 32 bits which have less precision, or something
It’s just by accident that with f32 you get 0.1 + 0.2 == 0.3. Try 0.1 + 0.6 == 0.7 for instance and you will get false in Rust while you get true in Javascript. Decimal numbers are not comparable at all to floats, for instance 1 / 3 is not a decimal number, which makes them pretty useless for many applications.
plz tell me theses are the stress buster questions which u and ur interviewer will laugh on after him asking abt, promises, event loops and other stuff.
Yeah that’s kind of the point haha. And while you’ll never see these things specifically, I actually think knowing them is a decent proxy for having a deep understanding of the language.
Jezuz, so much JS ready to ruin your day. An empty array is truthy?? Implicit string-> number conversion...but only sometimes where it's number -> string conversion instead!? Implicit bool -> number conversion?! My mind is melting...
Because it has to return a value like any other function, operator, etc. Types aren’t values. For example, you can’t return just the number type. You need a value to describe what type it is, and a string like “number” is a reasonable way to do that.
@@ConnerArdmanI suppose that is reasonable in JavaScript since there are not that many actual types (i.e. you can't define your own so you probably don't care about the robustness. Not to say it isn't robust, it just seems a bit unintuitive at first)
@@ConnerArdman you actually can return types e.g. `Number` from a function. There must be some other reason that JS doesn't do that. Try e.g. const n = () => Number ; n()(3)
That is not returning a type. Number is a constructor function for creating Number objects. I guess you could make an argument for returning these wrapper object constructors, but I think that would be _really_ messy.
Just had a doubt that are these test and things actually useful in the code like when I work with JavaScript I don't use all this stuff if something is there that I don't understand I learn it on the go is it the right approach or like I need to reevaluate?
If you used something in this video regularly, you would probably be doing something wrong haha. I think understanding how these things work can be a good proxy for understanding of how the language works, but this is just a fun quiz. It's not meant to be the most practical knowledge ever.
@@ConnerArdman yes, this. If you don't explicitly ensure that all of your variables are of the type you expect, or if you use operators on types for which they are not intended so that implicit coercion happens, then you deserve all you get. The coercion rules *are* specified and deterministic, but no-one should be using them.
It's not inconsistent, it's just a bit... weird lol. The first statement isn't using truthy/falsy at all, and I never said it was. true == [] is equivalent to Number(true) == Number([]), because when comparing booleans to other values it converts to numbers. True as a number is 1 and [] as a number is 0, hence why I come to the conclusion of false for the first statement (1 == 0 // false). The second statement however is different. Because of the order of operations, we do ![] first. The not operator (!) will actually use the truthy/falsy values as it only works on booleans. So in this case, since [] is truthy, ![] is equivalent to !true or false. This leaves us with true == false, which of course is false and doesn't need any more type conversions. And finally at the end, we have false + false, which converts to numbers again for addition, giving 0 + 0.
All this proves is that JavaScript is a shitty language made in a weekend. And all standards and tooling for it follow the same philosophy of rushed and esoteric for the dumbest reasons.
Rubbish. Perl's default sort functor is also a string sorter. A sort function has to have _some_ default functor so why should it be a numerical sort instead of a lexical sort?
lol those are useless, stupid ass questions. this ain't never happening in a real world project. I hate when interviewers ask those kind of questions, It just shows that I shouldn't have even bothered to participate in the process
i got them all right and got immediately hired by a FAANG company
no he didn't hes lying
Can confirm.
Nicee !!!
i got them all wrong and now i'm homeless
Why on earth does typeof return a string instead of the actual type
So [] == 0 == false if it's a number, and [] == true if it's a boolean, that makes a lot of sense. Thanks, javascript.
Empty array is evaluated the same way as empty object in js - it just substitutes the object/array with reference to heap (like 0xFFFFFFFFFFFF) which is true.
But Number([]) is super weird and makes no sense. Well, this code makes no sense, so why the result should make sense...
@@eugeneponomarov7429 Interesting. I don't write javascript, so I had no idea why it would work that way.
@@eugeneponomarov7429because determinism should be separate from the subjective perception of something making sense or not.
While this quiz is a fun way to test of your knowledge of Javascript, these scenarios are why we have "use strict" and linting rules.
what does strict mode do ? it abolishes all these activities
I see 1 good use case for String.raw: defining a string variable containing backslashes. For example, windows filepath. String.raw`D:\path\to\file`, which is more readable than "D:\\path\\to\\file". This can be applicable to any string value containing backslashes which you don't want to escape everytime. It can be even inlined SQL script which can contain string literals (not a good idea, but anyway)
personally was thinking with regex, if you needed to use the constructor (for whatever reason), which takes the representation of the regex *as a string*, in which you would have to double-escape any special chars (e.g. \d -> "\\d"). This would not be necessary using String.raw.
exactly. i’ve used raw strings all the time for defining static regex in python code. e.g., `r’my raw
string’`
Yep. I have a script that uses String.raw to store a Windows path in a variable.
Just use slashes for paths. Why would one use backslashes?
@@joshix833 windows’ path separator is the backslash; it’s necessary to use to delimit a path on windows
10:18 I haven’t heard of String.raw in JS but there is a similar feature in Dart. One use case for them is declaring regular expression string literals. You don’t have to deal with escaping certain characters etc.
love when people bring up they are a former faang employee. i don't bring up that I use to bag groceries at kroger.
Much like crossfitters, we are contractually obligated to bring it up at all possible moments
I recently used a version of String.raw in C# where instead you use the @ symbol before the string (string myString = @"my string contains "quotes" and stuff"), and this was for adding a SQL Server connection string to my app, so instead of using \ before the " to consider it part of the string itself, you use the raw value of the string which is everything contained within the outermost quotes
Floating point arithmetic caused me so many problems until I learned about it. Switched to all integers and convert to decimals.
String.raw is useful with creating regular expression dynamically
I surpringly got all correct except number cast of empty array in question 7
Nice! 👏👏👏
This is why I hate dynamic languages (a little 😅)
Dynamic languages are ok, automatic type conversion isn't.
Are you really projecting your hate towards JS onto other dynamic languages? Python doesn't have this skill issue, for instance
It’s an issue that can only happen in a dynamic language because it has to do some kind of type “guessing” since your types are not explicitly defined. I’m learning Elixir right now and I also don’t like the “ambiguity” of type sometimes - like having a list of mixed types. So it’s not just JS (although JS could be the worst offender).
That said, I still use JS and Python and as mentioned I’m learning Elixir - another dynamic language so no need to get defensive 😉
I take back my previous reply. Automatic type conversion does make a big difference.
just blame JS. the rules are so messy.
String.raw is pretty useful when you work with windows-like path in Node.js
For the floating point precision problem: Does JavaScript give you standard library tools to deal with errors in floats?
I'm just wondering because in other languages, like Rust or C, you can just cast 0.1 and 0.2 as f32 (Rust) or float (C) which then is equal to 0.3, so 0.1 + 0.2 == 0.3 is true when cast as f32.
Rust:
println!("{}", 0.1 as f32 + 0.2 as f32 == 0.3 as f32);
Even other interpreted languages like Python give you the 'decimal' module as part of the standard library, which lets you handle it like so:
Python:
from decimal import Decimal
print(Decimal('0.1') + Decimal('0.2') == Decimal('0.3'))
which returns true.
The Decimal module handles decimal numbers as exactly their mathematical equivalent (up to a certain cutoff, which can be manually extended).
the rust thing is really weird but surprisingly true
though I don't think it's comparable to the decimal lib in python
it's just that JS floats are 64 bit by default, and you're manually casting it to 32 bits which have less precision, or something
It’s just by accident that with f32 you get 0.1 + 0.2 == 0.3. Try 0.1 + 0.6 == 0.7 for instance and you will get false in Rust while you get true in Javascript.
Decimal numbers are not comparable at all to floats, for instance 1 / 3 is not a decimal number, which makes them pretty useless for many applications.
There isn't really a way to solve them in any language. It just happens to work out in some ways.
You can just do integer math to avoid it.
It's actually insane that we ended up on the timeline where JavaScript exists.
9/10, and only because I was fooled by the correct answer for `typeof NaN` not having string quotes around it so I had ruled it out.
Starts off wacky. Since in strict mode the first one would throw an error, not evaluate to anything. And modules are automatically strict mode.
plz tell me theses are the stress buster questions which u and ur interviewer will laugh on after him asking abt, promises, event loops and other stuff.
Looks like useful knowledge to debug weird code that some co-worker might have written, if they didn’t know those pitfalls 😅
Dude looks like Peewee Herman and the guy who played Polkadot man from The Suicide Squad.
When coding in Python, at least, I would use raw strings for regex
Only got 7/10 right, time to quit being a JS dev and start farming or something
Delete it Before interviewers come here.
This is quiz is filled with questions only related to javascript behaviors that are weird and most likely if you know what you do won't ever see.
Yeah that’s kind of the point haha. And while you’ll never see these things specifically, I actually think knowing them is a decent proxy for having a deep understanding of the language.
I got 8/10, the first one got me, I didn't even know that '0' means octal 😂 and what the fuck is string raw 😂😂
Re-title the video to “10 reasons to avoid JavaScript at all costs”
So i failed to answer all the ones which you answered right, but answered the one you answered wrong 😢
If we combine our powers, we’d be unstoppable…
@@ConnerArdmanOr fail all 100%
What is funny is i only knew the one you got wrong. I got a lot to learn 😂
Thank god, we dont send people into space using this language
Just wait and you'll see someone do it.
First time i see your channel look really cool
Jezuz, so much JS ready to ruin your day. An empty array is truthy?? Implicit string-> number conversion...but only sometimes where it's number -> string conversion instead!? Implicit bool -> number conversion?! My mind is melting...
I would like to hear your thoughts on Devin AI and it's impact on job market
why he looks like AI character. all time i was analysing his movements lol
Too much time working for the Zuccbot, so I’m still part lizard robot for now…
@@ConnerArdman are you for real a robot?
Why on earth does typeof return a string instead of the actual type
Because it has to return a value like any other function, operator, etc. Types aren’t values. For example, you can’t return just the number type. You need a value to describe what type it is, and a string like “number” is a reasonable way to do that.
@@ConnerArdmanI suppose that is reasonable in JavaScript since there are not that many actual types (i.e. you can't define your own so you probably don't care about the robustness. Not to say it isn't robust, it just seems a bit unintuitive at first)
@@ConnerArdman you actually can return types e.g. `Number` from a function. There must be some other reason that JS doesn't do that.
Try e.g. const n = () => Number ; n()(3)
That is not returning a type. Number is a constructor function for creating Number objects. I guess you could make an argument for returning these wrapper object constructors, but I think that would be _really_ messy.
@@ConnerArdman hmm, true, but constructor functions are _almost_ an analog for types, especially since the ES5 class syntax.
Just had a doubt that are these test and things actually useful in the code like when I work with JavaScript I don't use all this stuff if something is there that I don't understand I learn it on the go is it the right approach or like I need to reevaluate?
If you used something in this video regularly, you would probably be doing something wrong haha. I think understanding how these things work can be a good proxy for understanding of how the language works, but this is just a fun quiz. It's not meant to be the most practical knowledge ever.
@@ConnerArdman yes, this. If you don't explicitly ensure that all of your variables are of the type you expect, or if you use operators on types for which they are not intended so that implicit coercion happens, then you deserve all you get. The coercion rules *are* specified and deterministic, but no-one should be using them.
Leading zero becomes an octal number because… 0 looks like O?
These questions are stupid, no real world scenario would you have these.
My god JavaScript is a horrible language
hi can you make a video how much javascript is enough before react js , because someine tell me i should can build in big app with js , is that true
If you want to learn JavaScript and react do the Odin project it's amazing and very detailed.
There is no single threshold, it’s pretty subjective. You should be pretty comfortable with JavaScript though imo.
ua-cam.com/video/m55PTVUrlnA/v-deo.html
just start building at first, then you'll dive deeper and deeper
Cool vid!
NB: the questions are not always the same.
5:36 wth man, you are inconsistent with you own explanation. you took empty array as falsy in the first statement and truthy in the second statement
It's not inconsistent, it's just a bit... weird lol. The first statement isn't using truthy/falsy at all, and I never said it was. true == [] is equivalent to Number(true) == Number([]), because when comparing booleans to other values it converts to numbers. True as a number is 1 and [] as a number is 0, hence why I come to the conclusion of false for the first statement (1 == 0 // false). The second statement however is different. Because of the order of operations, we do ![] first. The not operator (!) will actually use the truthy/falsy values as it only works on booleans. So in this case, since [] is truthy, ![] is equivalent to !true or false. This leaves us with true == false, which of course is false and doesn't need any more type conversions. And finally at the end, we have false + false, which converts to numbers again for addition, giving 0 + 0.
@@ConnerArdman thanks for this detailed explanation. i understood what you meant here.
Lol, people actually defending the dumpster fire that is JS
Well it is right in the name Just Sucks
More videos like this
🫡
❤ from Kashmir
i learned something today:
Do NOT use javascript.
This video makes JS look really bad
Because it is.
All this proves is that JavaScript is a shitty language made in a weekend. And all standards and tooling for it follow the same philosophy of rushed and esoteric for the dumbest reasons.
“JavaScript default sort converts to strings first.” And this is why people don’t like JavaScript.
Rubbish. Perl's default sort functor is also a string sorter. A sort function has to have _some_ default functor so why should it be a numerical sort instead of a lexical sort?
me no no wanna
This language has to be a joke
Joke Script
lol those are useless, stupid ass questions. this ain't never happening in a real world project. I hate when interviewers ask those kind of questions, It just shows that I shouldn't have even bothered to participate in the process
This is why I avoid using JavaScript. It's a very nonsensical language
Javascript is just the most stupid programming language ever.
I HATE JAVASCRIPT!!!!!
people would k1ll somebody because of a programming language lol as long as javascript keeps paying my bills it can keep returning these weird values
JavaScript? More like JesuScript, beause you will be constantly saying Jesus Fucking Christ, What The Fuck is going on in the language?
JavaScript sucks
What a clown language. I hate it.
i gotHelloTwitter
world correct ...lol and i didn't see the answers before hand either ...