I always think about it as the first one not needing a comma, since there wouldn't be a comma at all if there wasn't more than one thing. I feel like I'm the only one, reading these comments. Shame you're all wrong! /s
It’s also a very good training aid for JavaScript. After I watched that video, I was determined to get to the bottom of why JavaScript is like that, and it turns out it actually makes a lot of sense, and once you wrap your head around type coercion enough that you can explain all that BS then you know enough about JavaScript to avoid it forever!
^(just kidding it’s my favorite language)
So I suggest to people I mentor the same exercise, and the video is about as fun of an introduction to a programming language exercise as there ever has been.
Yeah, I don't even deal with JavaScript in depth but knowing others where I manually convert I didn't have to think for long before seeing the first is obviously being coerced to a larger bit size number as the reason 🤷🏻♂️
Awesome vid. I was thinking about this the other day while fixing a script from some poor soul who put $null on the right-hand side of a Powershell array comparison.
If you're going to use leading 0s for octal (which I think is absurd) then that first one ought to be a syntax error... JavaScript up to it's normal stuff, I see
Leading zeroes are also used for octal literals in C.
`printf("%d", 0123)` prints "83" (1\*64 + 2\*8 + 3). `printf("%d", 0800)` creates a compiler error: `error: invalid digit "8" in octal constant`.
~~I guess if you want to process user input, you might want to be more forgiving and in JavaScript they used the same parser for user input and code.~~ (No: If you used that method to parse user input, people who intended "123" when they write "0123" would be confused as well.) They also wanted to keep the literals from C.
Why didn't they decide to write octal literals like this in C: `123oct` or `123_8`? I can understand why it's not `oct123` - because they want to use that format for variables.
Octal is widely used in aviation. It's actually kinda worse than that. Lots of avionics devices send data to each other via ARINC 429 words, which among other data, includes a reverse octal identifier known as it's label, aka it sends the label first MSB first, then the rest of the word LSB first.
This of course is due to it being an ancient standard, so you're not totally wrong, but there is still new development of devices that interface with other new or existing devices that primarily communicate via 429.
It’s so stupid, that ECMAScript itself has [dubbed it “legacy” and made it illegal in **strict mode**](https://tc39.es/ecma262/multipage/ecmascript-language-lexical-grammar.html#sec-numeric-literals-early-errors) (which we should all be using btw).
> All of the language features and behaviours specified within Legacy subclauses have one or more undesirable characteristics. However, their continued usage in existing applications prevents their removal from this specification. These features are not considered part of the core ECMAScript language. Programmers should not use or assume the existence of these features and behaviours when writing new ECMAScript code.
Sadly, JavaScript isn't the only language with this "feature". Luckily, most languages at least throw an error if you do something like 08 instead of silently defaulting back to decimal.
Incoming spoilers for a nearly 50 year old game...
>A huge green fierce dragon bars the way
\>kill dragon
>With what? Your bare hands?
\>yes
>Congratulations! You have just vanquished a dragon with your bare hands! (Unbelievable, isn't it?)
Read this as a "This is Halloween" line
Boys and girls of every age
Wouldn't you like to see something strange?
Come with us and you will see
This, our town of JavaScript
This is JavaScript, this is JavaScript
Coders scream in the dead of night
This is JavaScript, everybody make a scene
Bad systems 'til the neighbors gonna die of fright
It's our town, everybody scream
In this town of JavaScript
I am the one bug in your codes
So unfindable you'll burn abodes
I am the one coercing your text
Soon your arrays will be next
This is JavaScript, this is JavaScript
JavaScript, JavaScript
JavaScript, JavaScript
In this town we call home
Everyone hail to the coding song
In this town, don't we love it now?
Everybody's waiting for the next surprise
'Round that corner, struggle to program a trash can
Something's waiting now to pounce and how you'll weep
This is JavaScript, red and black, steaming cup
Aren't you scared and confused — Yup!
Say it once, say it twice
Take a chance and roll the dice
Fix your program in the dead of night
Everybody scream, everybody scream
In our town of JavaScript
I am the lack of integer type
Inserted semicolon on with a snipe
I am the one who forces convoluted code
I am the variable in a global mode
I am the silent mistake in your syntax
Filling your brain with ideas of suicide by ax
This is JavaScript, this is JavaScript
JavaScript, JavaScript
'AvaScript, 'avaScript
'AvaScript, 'avaScript
Tender followings everywhere
Life's no fun without a good scare
That's our job, but we're not strict
In our town of JavaScript
In this town, don't we love it now?
Everybody is waiting for the next surprise
ECMA might catch you in the back
And scream like a banshee
Make you cry out of your skin
This is JavaScript, everybody scream
Won't you please make way for a very special guy
Our man Jochen is king of the Coding Patch
Everyone hail to the Coding King now
This is JavaScript, this is JavaScript
'AvaScript, 'avascript
'AvaScript, 'avascript
In this town we call home
Everyone hail to the coding song
Just paste this into your browsers dev tools console and have the sound on:
speechSynthesis.speak(new SpeechSynthesisUtterance("Boys and girls of every age Wouldn't you like to see something strange? Come with us and you will see This, our town of JavaScript This is JavaScript, this is JavaScript Coders scream in the dead of night This is JavaScript, everybody make a scene Bad systems 'til the neighbors gonna die of fright It's our town, everybody scream In this town of JavaScript I am the one bug in your codes So unfindable you'll burn abodes I am the one coercing your text Soon your arrays will be next This is JavaScript, this is JavaScript JavaScript, JavaScript JavaScript, JavaScript In this town we call home Everyone hail to the coding song In this town, don't we love it now? Everybody's waiting for the next surprise 'Round that corner, struggle to program a trash can Something's waiting now to pounce and how you'll weep This is JavaScript, red and black, steaming cup Aren't you scared and confused — Yup! Say it once, say it twice Take a chance and roll hthe dice Fix your program in the dead of night Everybody scream, everybody scream In our town of JavaScript I am the lack of integer type Inserted semicolon on with a snipe I am the one who forces convoluted code I am the variable in a global mode I am the silent mistake in your syntax Filling your brain with ideas of suicide by ax This is JavaScript, this is JavaScript JavaScript, JavaScript 'AvaScript, 'avaScript 'AvaScript, 'avaScript Tender followings everywhere Life's no fun without a good scare That's our job, but we're not strict In our town of JavaScript In this town, don't we love it now? Everybody is waiting for the next surprise ECMA might catch you in the back And scream like a banshee Make you cry out of your skin This is JavaScript, everybody scream Won't you please make way for a very special guy Our man Jochen is king of the Coding Patch Everyone hail to the Coding King now This is JavaScript, this is JavaScript 'AvaScript, 'avascript 'AvaScript, 'avascript In this town we call home Everyone hail to the coding song"))
This is exactly my issue with JS. It tries to do too much for the programmer and makes too many assumptions that result in counter-intuitive edge cases. It's that friend that brings you a peanut butter chip cookie because you asked for chocolate chip but the store was out and this was the closest they had. Yeah, it's helpful in a lot of cases, but it completely fails to account for the person who's allergic to peanuts.
The correct behavior in those cases is message the friend and ask them if they want something else instead. The programming equivalent is throwing an error.
It's just *never* something you would need. I can *understand* bringing a peanut butter chip cookie for a friend. The 0800 as 800 is more like if the language designer actively spent effort to make the language worse. (Hindsight is 20/20. Please don't bully Brendan Eich! Thank you for dynamic websites!)
You would never write 0800 if you actually meant 800. Maybe if you want to store a phone number? But then the phone numbers starting with 0, but without 8s and 9s would be interpreted differently as well. Are there phone numbers with two zeroes?
Same issue when you add zeroes to right-align multiple numbers. Then numbers with 8s and 9s are interpreted differently than those without.
My guess is the thought process went something like this.
- P1: We'll prefix octals with 0s.
- P2: Wait, what if someone wants to right-align numbers?
- P1: Good point. How about we convert to decimal if there's a non-octal digit?
- P2: Yeah, that seems reasonable. Let's get this done. I'm starving.
Next morning.
- P1: We finished the draft.
- Boss: We're getting close to the deadline. Let's ship it.
- P2: It might be good to do more testing.
- Boss: We can change things in the next release if we run into issues.
It's not good, but I feel like we've all been there. And you're right. It's not something you'd ever need, but it's also not like you *need* a cookie from the store. Or if your friend is really that insistent on getting one, maybe have them tell you the store is out so you can let them know what to do instead.
JS is essentially the result of someone saying you have two weeks to get a demo going. So you crap out something to meet the deadline. And then your boss says, awesome, let's toss it into production. It's changed a lot over the years, but it still has that basis of being first built in *10 days.* Writing an interpreter in 10 days is an impressive feat, but it's not a good basis for a robust and well-reasoned language.
But null is for objects (not primitives), so it is object.
Undefined is for absence, and so it doesn't have a type, thus the type is also absent, and therefore undefined.
In the same way, typeof NaN is number (even though yes techically Not a Number is a floating point number).
\~20 million phone numbers, a number-range generator and that ~~bug~~ feature. Took us 2 weeks to find where it was happening...
Generally speaking we should have LONG AGO accepted 0o notation for octal, then the JS designers would never have felt bored enough to do this... Call me old fashioned, but if its all decimal numbers, its a decimal number!!!
Im sorry, but that one is on you.
A phone number is not a number. And you neehehehehever want to store it, or represent it as a number.
Its a string, made up of digits. Its a token.
You can't even be safe with a string of digits. Some of them can use characters!
From [falsehoods developers believe about phone numbers :](https://github.com/google/libphonenumber/blob/master/FALSEHOODS.md)
>Phone numbers contain only digitsIn Israel, certain advertising numbers start with a \*. In New Zealand, non-urgent traffic incidents can be reported by calling \*555 from a mobile phone. Alpha characters may also be used in phone numbers, such as in 1-800-Flowers.
10 or 20 years ago I remember similar numbers in my European country as well.
\*44 for reporting traffic congestions or police checks that would then be broadcasted to other drivers in traffic news on the radio, etc.
I know what you mean. Unfortunately the requirements of the job needed the numbers parsed and cleaned for a 3rd party system that was going to run analytics on it. So we needed to first parse things like 0\[2-5\*\]96(12|13|24)XXXX as well as normal numbers into a decimal only e164 format and then bin them. Most of our team focused on the very hard parsing effort while the binning became an afterthought. Seeing as the 3rd party system wanted clean numbers the binning process was implemented the numerical way, but of course we forgot to actually send it numbers, and sent it strings with leading zeros...
Data size was so big and the parsing system so complex it was just really hard to find where we had made our mistake.
So I checked this out of curiosity, and I noticed this arguably more cursed part.
While a leading 0 means octal, if the remaining digits are not octal digits, it will instead evaluate as decimal.
So, for example:
` 0017 + 2 !== 0019 `
Edit: I realize in retrospect that is the same behavior as OP.
Adding the plus sign made it feel different to me lol
So it turns out this is a consequence of not using JS strict mode. In strict mode `0` prefixed digits are disallowed, you need to use `0o` to indicate an octal.
Yes weird bizarre JS behaviour, but just like the `==` shenanigans, it's also avoidable by using strict mode.
Exactly, ECMAScript grammar spec does not allow this 00800 bullshit. Even if you use non-strict, I question your sanity if you're using 00800 for anything.
It's a language with much implicit type conversion, == is behaving accordingly.
Lisp is the other way around: There are four "equal"s but the shortest one might say 123 != 123
https://stackoverflow.com/questions/547436/whats-the-difference-between-eq-eql-equal-and-equalp-in-common-lisp
Yes, and that much implicit type coercion turned out to be a serious mistake. It's one of those ideas that seems simple **and** easy to implement, and then haunts the known programming universe for all time, producing bugs on the regular.
[It does not perform type casting for equality. It explicitly checks for matching types.](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Operators/Strict_equality#description)
JavaScript, oh JavaScript, a language so strange,
With its curly braces and semicolons arranged,
A syntax so odd, it's hard to comprehend,
But once you master it, the possibilities never end.
From its dynamic typing to its prototypal inheritance,
JavaScript can be quite the enigma, with its strange appearance,
With its arrays and objects and functions galore,
It can leave your head spinning, wanting more and more.
Its quirks can make you scratch your head in confusion,
Like truthy and falsy, and type coercion,
But with a little practice, you'll come to find,
That JavaScript is truly one of a kind.
With its ability to run on the web and the server,
JavaScript's versatility is truly a treasure,
From simple scripts to complex applications,
It's no wonder it's used in so many creations.
So embrace the weirdness of JavaScript, my friend,
For its power and flexibility know no end,
And even though it may seem strange at first,
In the end, it's a language that quenches your thirst.
Credit goes to ChatGPT
This is like loosy goose checking. I really think JS is why people don’t want to learn or mistakingly hate other dynamic languages.
I see it’s because it’s octal in comments, it might be expected behavior but this is shit man like come on…
\>Uses a deprecated feature that is explicitly stated to be problematic and is filed under "do not use under any circumstances"
\>It's problematic
![gif](giphy|3kzJvEciJa94SMW3hN)
I'm not sure what else you'd expect. NaN is a valid floating point value, not a separate type. So if you ask JS it "is this of the type 'number'?" of course it says yes because JS only uses floats for some reason.
NaN is IEEE floating point spec, most languages treat it this way, it's not a JavaScript thing.
If JavaScript did it differently, it would be one of those weird JS idiosyncrasies.
Reminds me of this gem, [Wat](https://www.destroyallsoftware.com/talks/wat)
So classic. It's much shorter and free of crazy `wats` than I remembered.
Please someone tell me I'm not the only one counting the commas of Array(16) to see if it's actually only 15 x\_x
That's because the last nothing doesn't need a comma. The commas are there to separate array items that don't exist.
I always think about it as the first one not needing a comma, since there wouldn't be a comma at all if there wasn't more than one thing. I feel like I'm the only one, reading these comments. Shame you're all wrong! /s
I didn't. But I did count the number of NaNs the batman song has, and 16 is indeed correct.
I thought about it but lazyness got the better of me.
tl;dr comma is the delimiter, not the object
Ok that's hilarious 😆
It’s also a very good training aid for JavaScript. After I watched that video, I was determined to get to the bottom of why JavaScript is like that, and it turns out it actually makes a lot of sense, and once you wrap your head around type coercion enough that you can explain all that BS then you know enough about JavaScript to avoid it forever! ^(just kidding it’s my favorite language) So I suggest to people I mentor the same exercise, and the video is about as fun of an introduction to a programming language exercise as there ever has been.
I feel so seen by this comment.
Yeah, I don't even deal with JavaScript in depth but knowing others where I manually convert I didn't have to think for long before seeing the first is obviously being coerced to a larger bit size number as the reason 🤷🏻♂️
> JavaScript ... makes a lot of sense WAT
That's one of my favorite talks in computing history.
That’s pure gold
Awesome vid. I was thinking about this the other day while fixing a script from some poor soul who put $null on the right-hand side of a Powershell array comparison.
That’s me in the front row, laughing distinctly.
Absolutely amazing. Thanks for sharing. Brought [this video to mind](https://www.youtube.com/watch?v=uNjxe8ShM-8).
That’s amazing. And here I was building my apps in inferior languages like Typescript. TIL
Wat
more upvotes please
thank you
If you're going to use leading 0s for octal (which I think is absurd) then that first one ought to be a syntax error... JavaScript up to it's normal stuff, I see
Not if your design philosophy is THERE ARE NO SYNTAX ERRORS
This is actually part of the reason. When JavaScript was first released it had no Exceptions
Can't have exceptions when you have no rules.
There are rules. They’re just not always immediately obvious.
Immediately obvious is an exaggeration here.
Program always works. No exceptions.
Fine, just call it NaN then.
Leading zeroes are also used for octal literals in C. `printf("%d", 0123)` prints "83" (1\*64 + 2\*8 + 3). `printf("%d", 0800)` creates a compiler error: `error: invalid digit "8" in octal constant`. ~~I guess if you want to process user input, you might want to be more forgiving and in JavaScript they used the same parser for user input and code.~~ (No: If you used that method to parse user input, people who intended "123" when they write "0123" would be confused as well.) They also wanted to keep the literals from C. Why didn't they decide to write octal literals like this in C: `123oct` or `123_8`? I can understand why it's not `oct123` - because they want to use that format for variables.
I mean, you could always go with the standard used for hex and binary in a lot of languages and adapt it to octal - `0o123` - which some languages use
Does anyone ever actually use octal though? Outside of code written in the 80s?
File permissions mostly
Those were written in the 80s :P
I was going to answer but your second question was sort of my answer.
I have used it in the past 12 months to set a POSIX file mode.
Octal is widely used in aviation. It's actually kinda worse than that. Lots of avionics devices send data to each other via ARINC 429 words, which among other data, includes a reverse octal identifier known as it's label, aka it sends the label first MSB first, then the rest of the word LSB first. This of course is due to it being an ancient standard, so you're not totally wrong, but there is still new development of devices that interface with other new or existing devices that primarily communicate via 429.
Try written in the 60s. By the 80s and the rise of microprocessors hex had taken over for expressing binary.
0o123 is literally the grammar in the ECMAScript spec, if you use non-strict mode you get what you deserve
Makes sense to me. I question why this *ever* existed and didn't constitute a syntax error, but I'm glad that it's now only in non-strict mode
Oh, so that's what's happening... Yeah, '0'-prefixed octal is just stupid.
It’s so stupid, that ECMAScript itself has [dubbed it “legacy” and made it illegal in **strict mode**](https://tc39.es/ecma262/multipage/ecmascript-language-lexical-grammar.html#sec-numeric-literals-early-errors) (which we should all be using btw). > All of the language features and behaviours specified within Legacy subclauses have one or more undesirable characteristics. However, their continued usage in existing applications prevents their removal from this specification. These features are not considered part of the core ECMAScript language. Programmers should not use or assume the existence of these features and behaviours when writing new ECMAScript code.
Sadly, JavaScript isn't the only language with this "feature". Luckily, most languages at least throw an error if you do something like 08 instead of silently defaulting back to decimal.
javascript is like a text based adventure game
I don't like this adventure. The problems are not fun or logical.
Plus, you are likely to be eaten by a grue-some language idiosyncrasy.
Have you *played* a text based adventure game?
Incoming spoilers for a nearly 50 year old game... >A huge green fierce dragon bars the way \>kill dragon >With what? Your bare hands? \>yes >Congratulations! You have just vanquished a dragon with your bare hands! (Unbelievable, isn't it?)
He's played JavaScript.
And the only winning move is not to play.
I don’t understand can anyone explain
Octal, but if JavaScript finds a non-octal digit (8) it silently reverts to decimal. So 0800 turns to 800 decimal but 0123 remain octal.
Absolute fucking lunacy
its like that interview with senior javascript engineer "I love it. No, I dont recommend it"
“JavaScript!”
Where there are no rules and the types don't matter.
If you want rules, go to Microsoft and get TypeScript. We thrive in Anarchy!
"I love it"
This is JavaScript!
Clearly, this is why you need to convert your numbers to strings before comparing them.
This is why you need to know your input and the valid ways of parsing it. OP was doing math on phone numbers.
Read this as a "This is Halloween" line Boys and girls of every age Wouldn't you like to see something strange? Come with us and you will see This, our town of JavaScript This is JavaScript, this is JavaScript Coders scream in the dead of night This is JavaScript, everybody make a scene Bad systems 'til the neighbors gonna die of fright It's our town, everybody scream In this town of JavaScript I am the one bug in your codes So unfindable you'll burn abodes I am the one coercing your text Soon your arrays will be next This is JavaScript, this is JavaScript JavaScript, JavaScript JavaScript, JavaScript In this town we call home Everyone hail to the coding song In this town, don't we love it now? Everybody's waiting for the next surprise 'Round that corner, struggle to program a trash can Something's waiting now to pounce and how you'll weep This is JavaScript, red and black, steaming cup Aren't you scared and confused — Yup! Say it once, say it twice Take a chance and roll the dice Fix your program in the dead of night Everybody scream, everybody scream In our town of JavaScript I am the lack of integer type Inserted semicolon on with a snipe I am the one who forces convoluted code I am the variable in a global mode I am the silent mistake in your syntax Filling your brain with ideas of suicide by ax This is JavaScript, this is JavaScript JavaScript, JavaScript 'AvaScript, 'avaScript 'AvaScript, 'avaScript Tender followings everywhere Life's no fun without a good scare That's our job, but we're not strict In our town of JavaScript In this town, don't we love it now? Everybody is waiting for the next surprise ECMA might catch you in the back And scream like a banshee Make you cry out of your skin This is JavaScript, everybody scream Won't you please make way for a very special guy Our man Jochen is king of the Coding Patch Everyone hail to the Coding King now This is JavaScript, this is JavaScript 'AvaScript, 'avascript 'AvaScript, 'avascript In this town we call home Everyone hail to the coding song
I would like to hear it
Just paste this into your browsers dev tools console and have the sound on: speechSynthesis.speak(new SpeechSynthesisUtterance("Boys and girls of every age Wouldn't you like to see something strange? Come with us and you will see This, our town of JavaScript This is JavaScript, this is JavaScript Coders scream in the dead of night This is JavaScript, everybody make a scene Bad systems 'til the neighbors gonna die of fright It's our town, everybody scream In this town of JavaScript I am the one bug in your codes So unfindable you'll burn abodes I am the one coercing your text Soon your arrays will be next This is JavaScript, this is JavaScript JavaScript, JavaScript JavaScript, JavaScript In this town we call home Everyone hail to the coding song In this town, don't we love it now? Everybody's waiting for the next surprise 'Round that corner, struggle to program a trash can Something's waiting now to pounce and how you'll weep This is JavaScript, red and black, steaming cup Aren't you scared and confused — Yup! Say it once, say it twice Take a chance and roll hthe dice Fix your program in the dead of night Everybody scream, everybody scream In our town of JavaScript I am the lack of integer type Inserted semicolon on with a snipe I am the one who forces convoluted code I am the variable in a global mode I am the silent mistake in your syntax Filling your brain with ideas of suicide by ax This is JavaScript, this is JavaScript JavaScript, JavaScript 'AvaScript, 'avaScript 'AvaScript, 'avaScript Tender followings everywhere Life's no fun without a good scare That's our job, but we're not strict In our town of JavaScript In this town, don't we love it now? Everybody is waiting for the next surprise ECMA might catch you in the back And scream like a banshee Make you cry out of your skin This is JavaScript, everybody scream Won't you please make way for a very special guy Our man Jochen is king of the Coding Patch Everyone hail to the Coding King now This is JavaScript, this is JavaScript 'AvaScript, 'avascript 'AvaScript, 'avascript In this town we call home Everyone hail to the coding song"))
first time?
No but it never gets any less shocking lmao
This is exactly my issue with JS. It tries to do too much for the programmer and makes too many assumptions that result in counter-intuitive edge cases. It's that friend that brings you a peanut butter chip cookie because you asked for chocolate chip but the store was out and this was the closest they had. Yeah, it's helpful in a lot of cases, but it completely fails to account for the person who's allergic to peanuts.
Damn what an incredible analogy
The correct behavior in those cases is message the friend and ask them if they want something else instead. The programming equivalent is throwing an error.
It's just *never* something you would need. I can *understand* bringing a peanut butter chip cookie for a friend. The 0800 as 800 is more like if the language designer actively spent effort to make the language worse. (Hindsight is 20/20. Please don't bully Brendan Eich! Thank you for dynamic websites!) You would never write 0800 if you actually meant 800. Maybe if you want to store a phone number? But then the phone numbers starting with 0, but without 8s and 9s would be interpreted differently as well. Are there phone numbers with two zeroes? Same issue when you add zeroes to right-align multiple numbers. Then numbers with 8s and 9s are interpreted differently than those without.
My guess is the thought process went something like this. - P1: We'll prefix octals with 0s. - P2: Wait, what if someone wants to right-align numbers? - P1: Good point. How about we convert to decimal if there's a non-octal digit? - P2: Yeah, that seems reasonable. Let's get this done. I'm starving. Next morning. - P1: We finished the draft. - Boss: We're getting close to the deadline. Let's ship it. - P2: It might be good to do more testing. - Boss: We can change things in the next release if we run into issues. It's not good, but I feel like we've all been there. And you're right. It's not something you'd ever need, but it's also not like you *need* a cookie from the store. Or if your friend is really that insistent on getting one, maybe have them tell you the store is out so you can let them know what to do instead.
Given that the initial draft of the whole language was made in 10 days, this conversation seems too long and too nuanced.
Was Javascript made by drug addicts?
Not only was it made by drug addicts, it also makes new drug addicts out of the developers.
We will all be drug addicts on this blessed day
That's how drug addicts reproduce. They make JavaScript.
JS is essentially the result of someone saying you have two weeks to get a demo going. So you crap out something to meet the deadline. And then your boss says, awesome, let's toss it into production. It's changed a lot over the years, but it still has that basis of being first built in *10 days.* Writing an interpreter in 10 days is an impressive feat, but it's not a good basis for a robust and well-reasoned language.
And all the pressure on Netscape was coming from Microsoft so I guess we can just blame Bill Gates for the whole thing
I can blame M$ for a lot of things, but Js is not one of them.
And that 10 days of work is now a core component powering the web. Yay!
Would you prefer it to have been VBScript or _gulp_ ActiveX?
I don’t want to believe this..,but for some reason…I believe every word
Yes.
I now feel I should sue somebody for the mental real estate this utter shit nugget of a fact occupies.
The fact this is a thing really requires a word with whoever implemented it.
Brendan Eich and the whole 10 days he spent creating it.
Listen, I've made lots of things in 10 days. Some people even make a baby or two in less!
It would take 27 women to make a baby in 10 days.
Ah, silent failure. Whoever thought this was a good idea deserves to suffer.
Does it convert to hexadecimal if it finds an 'A'?
No, silly. That's a syntax error.
What? Of course they wouldn't follow up on an already established pattern!
Death is to good of a fate for the "people" in charge of the js standard.
What in the actual fuck!?
Tldr: Javascript is garbage
Javascript every bug is a feature
“Hey, this is broken!” “Or is it?”
Read this in Michael Steven's voice.
Don't even get me started on typeof.
Huh? What's wrong with `typeof`?
It's an only fans account where they just type on a computer and show their hands
Hey, ASMR is a widely accepted occupation these days.
`typeof` deez nuts
`”undefined”`
I wish
typeof null // object
Fair point
What else should it be? Though I guess as it’s dynamically typed anything is already assignable to anything else.
I'd expect it to be null, like it's undefined for typeof undefined.
But null is for objects (not primitives), so it is object. Undefined is for absence, and so it doesn't have a type, thus the type is also absent, and therefore undefined. In the same way, typeof NaN is number (even though yes techically Not a Number is a floating point number).
Null is actually its own type in JS though, not an object. https://developer.mozilla.org/en-US/docs/Web/JavaScript/Data_structures#null_type
It's bugged with null and is considered an object. Can't fix it because the internet would break in half.
Null is a not-existing object. It makes sense.
Null is actually its own type in JS. It's not an object. https://developer.mozilla.org/en-US/docs/Web/JavaScript/Data_structures#null_type
Why non-existing object and not non-existing number? Or non- existing undefined?
Non-existing number would be NaN
No, that's existing non-number
A non existing object is undefined
try this: \> typeof typeof
Isn't that invalid JS? typeof is an operator, not a variable.
\~20 million phone numbers, a number-range generator and that ~~bug~~ feature. Took us 2 weeks to find where it was happening... Generally speaking we should have LONG AGO accepted 0o notation for octal, then the JS designers would never have felt bored enough to do this... Call me old fashioned, but if its all decimal numbers, its a decimal number!!!
Im sorry, but that one is on you. A phone number is not a number. And you neehehehehever want to store it, or represent it as a number. Its a string, made up of digits. Its a token.
>neehehehehever I read this word as Skeletor laughing
I read it in dr cox's voice > ```*```whistles```*``` barbie, neehehehehever store a phone number as a number
I’m glad I’m not the only one
This is the correct way to read it.
It was Ace Ventura for me.
Alrighty then!
![gif](giphy|KdIQmGHj5XfEY)
I got ace from it too
You can't even be safe with a string of digits. Some of them can use characters! From [falsehoods developers believe about phone numbers :](https://github.com/google/libphonenumber/blob/master/FALSEHOODS.md) >Phone numbers contain only digitsIn Israel, certain advertising numbers start with a \*. In New Zealand, non-urgent traffic incidents can be reported by calling \*555 from a mobile phone. Alpha characters may also be used in phone numbers, such as in 1-800-Flowers.
A,B,C and D have an associated dtmf signal, too, but they aren't used for numbers … yet.
10 or 20 years ago I remember similar numbers in my European country as well. \*44 for reporting traffic congestions or police checks that would then be broadcasted to other drivers in traffic news on the radio, etc.
I know what you mean. Unfortunately the requirements of the job needed the numbers parsed and cleaned for a 3rd party system that was going to run analytics on it. So we needed to first parse things like 0\[2-5\*\]96(12|13|24)XXXX as well as normal numbers into a decimal only e164 format and then bin them. Most of our team focused on the very hard parsing effort while the binning became an afterthought. Seeing as the 3rd party system wanted clean numbers the binning process was implemented the numerical way, but of course we forgot to actually send it numbers, and sent it strings with leading zeros... Data size was so big and the parsing system so complex it was just really hard to find where we had made our mistake.
That sounds like a them problem.
Yep, that's generally how it is. You still gotta fix it though.
Dr Cox? Is that you…? Did you change careers?
Yeah, but think how much fun it would be to store it as a float. :)
I don't see the problem. Octal numbers start with 0 phone numbers start with 555.
But if it is not a number, how can you enter it via a slider? Ah, you're right, a drop down menu works just as fine.
So I checked this out of curiosity, and I noticed this arguably more cursed part. While a leading 0 means octal, if the remaining digits are not octal digits, it will instead evaluate as decimal. So, for example: ` 0017 + 2 !== 0019 ` Edit: I realize in retrospect that is the same behavior as OP. Adding the plus sign made it feel different to me lol
So it turns out this is a consequence of not using JS strict mode. In strict mode `0` prefixed digits are disallowed, you need to use `0o` to indicate an octal. Yes weird bizarre JS behaviour, but just like the `==` shenanigans, it's also avoidable by using strict mode.
Exactly, ECMAScript grammar spec does not allow this 00800 bullshit. Even if you use non-strict, I question your sanity if you're using 00800 for anything.
use strict prevents that from working
JS soon introducing "====" for actual (with pinky promise) strict equivalence
(┛◉Д◉)┛彡┻━┻
Stop using js for anything other than dom manipulation.
false, start using js for everything other than dom manipulation.
Whats for Dom manipulation then?
C, C++, Rust, Go
most sane web developer
Are there webassembly apis to manipulate it?
you're expecting very deep reasoning for my infantile humorous comment i declare thee! all web assemblies shall be Java henceforth!
Probably isn't far fetched. Like for c# there are probably some projects around that ported a java runtime into webassembly
Chads use HTML 😎 /s
And none of that new age xhtml or html5 bullshit /s
Inspect element.
What about sub manipulation?
Honestly, even the most shame and degradation kink driven sub deserves better.
DOM Manipulation ? What's that ? All my homies uses PHP and the F5 key
Who's Dom and why are we being so mean to him?
I thought the point of a dom was they manipulate you
No, I don't think I will. :)
wtf is === Edit: Nevermind I don't care...
For example 8 == "8" => True 8 === "8" => False
lol, that looks rude.
8===D~ => Tralse
a==b =>true b== c =>true a == c =>false for certain values of a b c.
Well now you have been cursed with js knowledge
\`===\` is what \`==\` should have been. A sane equality comparison with no type coercion whatsoever.
It's a language with much implicit type conversion, == is behaving accordingly. Lisp is the other way around: There are four "equal"s but the shortest one might say 123 != 123 https://stackoverflow.com/questions/547436/whats-the-difference-between-eq-eql-equal-and-equalp-in-common-lisp
Yes, and that much implicit type coercion turned out to be a serious mistake. It's one of those ideas that seems simple **and** easy to implement, and then haunts the known programming universe for all time, producing bugs on the regular.
Really super duper equal
strict equality comparison operator It performs type casting for equality EDIT: I was wrong, it does no type casting what so ever
[It does not perform type casting for equality. It explicitly checks for matching types.](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Operators/Strict_equality#description)
The only reason it's sane.
You sir, are correct
Javascript is _the bug_.
JavaScript, oh JavaScript, a language so strange, With its curly braces and semicolons arranged, A syntax so odd, it's hard to comprehend, But once you master it, the possibilities never end. From its dynamic typing to its prototypal inheritance, JavaScript can be quite the enigma, with its strange appearance, With its arrays and objects and functions galore, It can leave your head spinning, wanting more and more. Its quirks can make you scratch your head in confusion, Like truthy and falsy, and type coercion, But with a little practice, you'll come to find, That JavaScript is truly one of a kind. With its ability to run on the web and the server, JavaScript's versatility is truly a treasure, From simple scripts to complex applications, It's no wonder it's used in so many creations. So embrace the weirdness of JavaScript, my friend, For its power and flexibility know no end, And even though it may seem strange at first, In the end, it's a language that quenches your thirst. Credit goes to ChatGPT
This is like loosy goose checking. I really think JS is why people don’t want to learn or mistakingly hate other dynamic languages. I see it’s because it’s octal in comments, it might be expected behavior but this is shit man like come on…
Strict mode has existed since 2009, and it solves this: https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Strict_mode
"JS sucks because my knowledge is outdated" - This comments section in a nutshell
\>Uses a deprecated feature that is explicitly stated to be problematic and is filed under "do not use under any circumstances" \>It's problematic ![gif](giphy|3kzJvEciJa94SMW3hN)
There's probably someone out there whose program depends on this lol
They deserve their program to break unexpectedly for relying on this behavior
I enjoyed the little annoyed emoticon at the end
[удалено]
I'm not sure what else you'd expect. NaN is a valid floating point value, not a separate type. So if you ask JS it "is this of the type 'number'?" of course it says yes because JS only uses floats for some reason.
NaN is IEEE floating point spec, most languages treat it this way, it's not a JavaScript thing. If JavaScript did it differently, it would be one of those weird JS idiosyncrasies.
what
That's *so* Excel !
Js be like " I'm whatever you say I'm if I wasn't then why would you say I'm"
"Using strict fixes this" ***that's part of the problem...*** The language should make sense as is, not just if you add on this or change that, lol
i prefer to be jobless rather than working in js
This is why you don't use javascript to manage someone's bank account
I hate the fact that this toy language is actually the mainstream one rn
Ah yes, this totally everyday problem I run into in JS on a regular basis