r/node • • May 24 '21

20 JavaScript Concepts you should know as a JavaScript Programmer!

https://blog.devgenius.io/20-javascript-concepts-you-should-know-as-a-javascript-programmer-c04d7b1a8d6e?sk=cc9a655f3a07686a9a1cdd4825c73e18
62 Upvotes

17 comments sorted by

49

u/inabahare May 24 '21

1: You're missing function scope

3: Var declares the variable to the current function scope

6: So this one is just completely misleading. Wrapping something in a promise doesn't make it async pr. default. Long loops and other heavy code will still block the rest of your code.

8: Doesn't really make much sense. You're basically saying "yeah so there's this thing called prototypes and they're the reason dates are dates and arrays are arrays"

9: ES6 is from 2015.

9a: Please don't use var. And please don't say "in some cases" without naming those cases

9b: "Noting more" is wrong. They also use the same function scope as the function they're called in. IE:

function test() {
    const test2 = () => // Has the same scope as test
}

9c: Functional programming isn't just "programming with functions".

11: If it's so important then why aren't you explaining it? Or at least showing it?

12: Why aren't you saying what it is? "It's a thing you can do in Javascript" isn't a really good description

13: Same as above. "Methods are things that exist" is kinda silly.

17: Same as above.

18: Could also be a good place to describe truthy and falsy values

19: Load pages and data in general.. It's not even showing an example, which would be the perfect place.

Bonus: If you google ECMAScript you find that it's not actually the official name for JS, but the language they follow. Actionscript is another language that follows that standard

46

u/Philosufur May 24 '21

Guess I will not read this article lol

3

u/derpotologist May 24 '21 edited May 24 '21

4: closures are not JavaScript concepts

Also if you put a closure inside another function it wouldn't have access to the global scope

21

u/AtroxMavenia May 24 '21

This article has a lot of bad or straight up wrong information.

17

u/Jakek1 May 24 '21

Another medium listicle about JS full of misinformation or missing anything of real value? Color me surprised.

11

u/Skhmt May 24 '21

What does curry() do in the currying example? That's not built in to the language right?

What's the advantages of currying?

9

u/nextwiggin4 May 24 '21

You’re correct, it’s not built into the language. It’s a technique used in functional programming. In this example sum has two arguments that both need to be supplied at the same time for the function to execute. By currying it, he turned it into a function that accepts the first argument then returns another function that accepts the second argument, which then returns the sum.

This example is pretty bland, but it’s a very powerful technique for managing scope and state in a functional way.

2

u/conventionalWisdumb May 24 '21

The example uses a sum function but imagine that instead it’s say a model from a DB, and the other is a field off the model the user wants that comes from the FE as “model:field” and you have rules for transforming the different data from the model to friendly string. You don’t want to add all the extra non-model concerns to the model, but you still want to be able to pass it around to be used by other code bound to a specific model instance. You create a curried function where the first function takes the model as an arg and the second takes the field string. You can pass the model to the first early and then other code doesn’t have to know where the model data came from. They just use the second function and pass it the field strings they do know about.

1

u/burkybang May 24 '21

Here's a much better read on currying

https://javascript.info/currying-partials

1

u/Buckwheat469 May 24 '21

It looks like the line was taken directly from this link but the OP didn't take the time to read the read and explain it.

The log() example in the above link best explains it. You can use currying to partially execute a function and then complete the execution later. The examples for sum(a)(b) show this execution happening immediately, but you can imagine a more complex example that performs a conversion on the first parameter, then takes another parameter and finalizes the result. Perhaps this is something like sumDate or mergeData or concat (such as concat(Promise1)(Promise2)).

The Log example shows that you can initialize the curried function with a value, such as the date string, then when you execute the curried variable with a new argument it appends the argument to the date and outputs it in the log.

6

u/oneandmillionvoices May 24 '21

DOM is not javascript concept.

It actually is quite blurred what "concept" means in that article.

you've mentioned currying, but left out partial application which is IMO more relevant when talking about javascript.

I also miss the word about javascript interpreter what is event loop, what is stack and heap and how do async calls work. (although that presentation by Philip Roberts is exceptional. )

12

u/VeraLapsa May 24 '21

I personally got a laugh at

An arrow function is just a fancy way to write a function in javascript. Nothing more.

let's loot at the MDN for differences from normal functions.

Does not have its own bindings to this or super, and should not be used as methods.

Does not have arguments, or new.target keywords.

Not suitable for call, apply and bind methods, which generally rely on establishing a scope.

Can not be used as constructors.

Can not use yield, within its body.

It's a bit more than just fancy way to write a function.

1

u/derpotologist May 24 '21

Closure is not a JavaScript concept

Bad title maybe? I was hoping for an article unique to JavaScript

6

u/burnblue May 24 '21

I can tell from jump that the whole article could use some work, but to start it at least fix this

But, you **can **access a variable defined in local scope from global scope until it is returned from functions.

Also,

ES6 — The New JavaScript . ES6 is a second revision in javascript.

What? And somewhere else you use the year name format EcmaScript 2017. Not a great history lesson

2

u/cheese_wizard May 24 '21

If you don't what the DOM is, then you probably shouldn't be learning about currying. I.e. who is the target audience here?

2

u/vexii May 24 '21

never mentions that class is syntax sugar for prototype and never mentions how classes/prototypes are fundamentally different then classes on oop languages.

1

u/vyashole May 24 '21

This article is missing a lot of things and is partly wrong about the things it doesn't miss.

curry isn't even a javascript concept. It is of course possible to do in j's, but the article doesn't even show how. It's a functional programming concept and the example doesn't do a good job of explaining why it is useful.