News for hackers. Stuff that matters.
Re:Modern Javascript: Everything you missed over the last 10... by austincheney on Saturday May 15, 2021 @01:30PM (#27167162)
There are a couple of things that JavaScript got so incredibly correct:

* Lexical scope natively without syntax or conventions

* Functions as first class citizens

* Inheritance, classes, OOP are not forced on you and can be ignored/omitted entirely from your code

Those few things are what has kept me hooked on the language.

> Node is not ECMAScript in a server-side ECMAScript engine, it's JavaScript in a browser JavaScript engine.

What does that even mean? The APIs are completely unrelated and Node does different things that don’t make sense in the browser.

Re:Modern Javascript: Everything you missed over the last 10... by titzer on Saturday May 15, 2021 @01:43PM (#27167283)
> * Lexical scope natively without syntax or conventions

I assume you mean over the alternative, dynamic scoping like in e-Lisp. But you realize that JavaScript's scoping rules are entirely wonky, e.g. that "var" declarations are lifted to the function level?

Re:Modern Javascript: Everything you missed over the last 10... by errantspark on Saturday May 15, 2021 @01:51PM (#27167342)
Right but we have `let` now which solves that problem.
Re:Modern Javascript: Everything you missed over the last 10... by titzer on Saturday May 15, 2021 @04:21PM (#27168633)
Not completely, `let` also has a weird temporal dead zone[1], which is basically a dynamic check.

[1] https://www.freecodecamp.org/news/what-is-the-temporal-dead-...

Re:Modern Javascript: Everything you missed over the last 10... by IshKebab on Sunday May 16, 2021 @03:55AM (#27171996)
That's a good thing, and I'm not sure what you mean about it being a dynamic check.
Re:Modern Javascript: Everything you missed over the last 10... by titzer on Sunday May 16, 2021 @01:38PM (#27175428)
It's a dynamic error if you access a let-bound variable before it is actually initialized. In most other languages that have lexically-scoped declarations, it simply would not be visible. So I think JS's choice is actually a regression.
Re:Modern Javascript: Everything you missed over the last 10... by austincheney on Saturday May 15, 2021 @01:48PM (#27167312)
To be more specific the term is hoist which means the declarations are pushed to the top of the scope at run time for maximum availability, and var is function scoped instead of block scoped. Block scoping is often more specific because a function body is a block as well.
Re:Modern Javascript: Everything you missed over the last 10... by hwillis on Saturday May 15, 2021 @01:54PM (#27167365)
var is a terrible example of that. Just don't use it.

A good example would be the scoping in for loops and maybe arrow functions. For loops are goofy but virtually never an issue, and arrow functions are awesome.

Re:Modern Javascript: Everything you missed over the last 10... by cush on Monday May 17, 2021 @05:55AM (#27181693)
They were referring to `let`
Re:Modern Javascript: Everything you missed over the last 10... by hollerith on Saturday May 15, 2021 @02:37PM (#27167735)
>a couple of things that JavaScript got so incredibly correct: . . . Lexical scope natively without syntax or conventions

What language of the last 28 years doesn't "natively" lexically scope its variables?

Re:Modern Javascript: Everything you missed over the last 10... by icedchai on Saturday May 15, 2021 @02:52PM (#27167847)
Not Javascript. If I forget a var or let, it's global.
Re:Modern Javascript: Everything you missed over the last 10... by austincheney on Saturday May 15, 2021 @03:22PM (#27168073)
Strict mode throws an error on implied globals. Use of modules forces strict mode.
Re:Modern Javascript: Everything you missed over the last 10... by icedchai on Saturday May 15, 2021 @03:53PM (#27168400)
And that's all "extra" syntax.
Re:Modern Javascript: Everything you missed over the last 10... by JoyrexJ9 on Saturday May 15, 2021 @04:01PM (#27168474)
strict mode is the default in everything now and had been for many many years.
Re:Modern Javascript: Everything you missed over the last 10... by icedchai on Saturday May 15, 2021 @05:14PM (#27169093)
It isn't the default for a browser "<script>" tag.
Re:Modern Javascript: Everything you missed over the last 10... by xigoi on Saturday May 15, 2021 @05:54PM (#27169371)
It's the default for <script type="module">, which you should use anyway for anything serious.
Re:Modern Javascript: Everything you missed over the last 10... by z3t4 on Saturday May 15, 2021 @02:46PM (#27167807)
JavaScript is different in that it use the function as the lexical scope rather then the angel brackets. This forces you to think about the code as functions, rather then blocks. And in turn helps you think of the code in three dimensions where time is one dimension, making it easier to understand code that runs asynchronously.
Re:Modern Javascript: Everything you missed over the last 10... by z3t4 on Sunday May 16, 2021 @05:21AM (#27172400)
Because people coming from other languages find this confusing the let (and const) keyword was specified (ES6/2015) for block/angel-bracket lexical scope. Whereas var is function scoped.
Re:Modern Javascript: Everything you missed over the last 10... by dclowd9901 on Saturday May 15, 2021 @03:05PM (#27167938)
And here I thought scope was kind of disaster in JS:

- `const fooFunc = () => {}` is treated differently than `function fooFunc() {}` in declaration and subsequent access.

- A function's invocation context changes depending on how it was declared (fat arrow vs. function declaration)

Don't get me wrong: I love JS, but this is not one of the things I felt made it intuitive.

Re:Modern Javascript: Everything you missed over the last 10... by austincheney on Saturday May 15, 2021 @03:23PM (#27168087)
The this context changes, but I recommend developers not use this. That isn’t a scope issue though.
Re:Modern Javascript: Everything you missed over the last 10... by mweberxyz on Saturday May 15, 2021 @03:30PM (#27168145)
There would be no point in having two ways to do the exact same thing if function-style declaration and arrow-style declaration implementations were identical. Why would they add a new feature to the language if it was purely syntactic sugar?
Re:Modern Javascript: Everything you missed over the last 10... by senthil_rajasek on Saturday May 15, 2021 @03:13PM (#27168002)
>> Node is not ECMAScript in a server-side ECMAScript engine, it's JavaScript in a browser JavaScript engine.

>What does that even mean? The APIs are completely unrelated and Node does different things that don’t make sense in the browser.

I have taken the privilege of rewriting the quoted part of the parent comment,

Node runs javascript on the server side in an engine built for the browser. It does not run ECMAScript with an engine specially made for server side apps.

Re:Modern Javascript: Everything you missed over the last 10... by IshKebab on Sunday May 16, 2021 @03:58AM (#27172006)
This comment is so weird. JavaScript got scoping completely wrong, and none of those were particularly novel when it was designed and they are almost universal now so I don't know why they would keep you hooked on JavaScript!

Maybe try some other languages...

Re:Modern Javascript: Everything you missed over the last 10... by galangalalgol on Saturday May 15, 2021 @01:37PM (#27167229)
That last bullet is my main complaint with java and c#.
Re:Modern Javascript: Everything you missed over the last 10... by wvenable on Saturday May 15, 2021 @02:08PM (#27167489)
C# just removed the requirement to start code with a class or a main method; you can just start typing into the file.
Re:Modern Javascript: Everything you missed over the last 10... by metaltyphoon on Saturday May 15, 2021 @03:34PM (#27168188)
I like this so much. In fact they are investigating the idea of #!/usr/bin/dotnet on a .cs file!
Re:Modern Javascript: Everything you missed over the last 10... by wernercd on Sunday May 16, 2021 @12:18AM (#27171199)
And those things are outweighed by things JavaScript got so incredibly wrong... like === vs == and some of the weirdness when you GASP use == as any other language would do.

JS is like PHP... only a popular language because it's been around a long time and it's easy to get started. Otherwise, there are SOOO many better programming language out that the ONLY reason JS still has traction is it became the "default" web language.