Live data from Hacker News

JavaScript fundamentals before learning React

robinwieruch.de

11–20 of 72 posts

Re: JavaScript fundamentals before learning React

#11
post #8

Hey, author here :) I am curious about your experiences using/learning React. Are there any other JavaScript topics which are important when starting out with React? Would be great hearing your opinion!

Formatting strings (template literals [1]) comes up frequently for constructing ids/refs/various other props.

1. https://developer.mozilla.org/en-US/docs/Web/JavaScript/Refe...

Re: JavaScript fundamentals before learning React

#12

This article has a lot to offer a JS + React beginner so it feels lame to reply to some tiny part of it, but this bit is a constant error propogated in the ecosystem: > Even though it is possible to mutate the inner properties of objects and arrays when using const, the variable declaration shows the intent of keeping the variable immutable though. let and const only control mutability of the reference. They say noth…

'const prevents reassignment' is a much simpler way of saying that.

Mutability doesn't need to come into it.

Re: JavaScript fundamentals before learning React

#13
post #8

Hey, author here :) I am curious about your experiences using/learning React. Are there any other JavaScript topics which are important when starting out with React? Would be great hearing your opinion!

hey there, nice write-up

two minor things that you might include are

1: rest in the context of function args

2: short circuiting: e.g. `isLoading && `

Re: JavaScript fundamentals before learning React

#14
post #8

Hey, author here :) I am curious about your experiences using/learning React. Are there any other JavaScript topics which are important when starting out with React? Would be great hearing your opinion!

Nice writeup!

I wrote a tutorial that would be the next step to yours, called React From Zero[0] I try to teach React here with the basic JavaScript knowledge most people already have.

[0] https://github.com/kay-is/react-from-zero

Re: JavaScript fundamentals before learning React

#15
post #12

This article has a lot to offer a JS + React beginner so it feels lame to reply to some tiny part of it, but this bit is a constant error propogated in the ecosystem: > Even though it is possible to mutate the inner properties of objects and arrays when using const, the variable declaration shows the intent of keeping the variable immutable though. let and const only control mutability of the reference. They say noth…

'const prevents reassignment' is a much simpler way of saying that. Mutability doesn't need to come into it.

I agree with you, but I’ve cleared up this confusion with a number of colleagues. People coming from languages that have a truly immutable “const” find the keyword confusing in js.

Re: JavaScript fundamentals before learning React

#16
post #8

Hey, author here :) I am curious about your experiences using/learning React. Are there any other JavaScript topics which are important when starting out with React? Would be great hearing your opinion!

This is great! Great write up and good idea on what to actually write about.

One suggestion I'd make is to use ES6 template literals over concatenation, since you're using other ES6 constructs anyway.

    getName() {
      return `${this.firstname} ${this.lastname}`;
    }
Cleaner and less error prone. On our team we had a convention to only use backticks when we intended to combine strings, so that if you ever saw a backtick, you knew a string was being built, likely for output.

Re: JavaScript fundamentals before learning React

#17
I had the chance/experience to train a new team in Vue.js (and thus modern JS) which I imagine is similar to people learning React. I noticed the same thing as the author - the new JS frameworks are "all about JavaScript". Without a solid knowledge of how JS works, and ES6, learning any of them is difficult. When realizing this, the main things I focused on what getting people to understand JavaScript, _then_ start to make use of the framework's more powerful features.

I also noticed a lot of people interpreting `const` as "you can not change this, ever". It is short for constant, after all.

Re: JavaScript fundamentals before learning React

#18
post #8

Hey, author here :) I am curious about your experiences using/learning React. Are there any other JavaScript topics which are important when starting out with React? Would be great hearing your opinion!

It’s worth noting that using the fat arrow syntax for class functions make them exponentially harder to unit test because they do not exist on the Prototype of the component, but are instead only initialized when the class is initialized.

If you are trying to unit test a function that calls another function in the same class you cannot mock the second one it if it is a fat arrow.

Re: JavaScript fundamentals before learning React

#19
post #6
post #4

Earlier quoted context omitted.

Author here {: Yes, what you are saying here is what I meant. I didn't want to mix in the whole topic around "passing by value or reference" in this short teaser. Hi Swizec :wave: :)

Hi, Robin. Then you may want to say that `const` guarantees that the name will remain bound to that object. The great-GP is correct in that `const` has nothing to do with immutability besides that. It doesn't necessarily conveys an intent of inner immutability. It just states that whatever is in the variable will stay there until it goes out of scope. Using `const` whenever possible is good advice, off course.

It's been astonishing to me how people switched from var to let, but seem confused as to when to use const. I use const wherever I can since it's more appropriate for non-changing variables, and it helps me more easily visualize how a variable is being used in a block. But in other people's code I see a lot of letting all over the place. Maybe it's because of those articles saying to use let instead of var, but glossing over const.

Re: JavaScript fundamentals before learning React

#20
post #12

Earlier quoted context omitted.

'const prevents reassignment' is a much simpler way of saying that. Mutability doesn't need to come into it.

I agree with you, but I’ve cleared up this confusion with a number of colleagues. People coming from languages that have a truly immutable “const” find the keyword confusing in js.

Yea, I think const in JS alludes to the way const works in C++.

If someone knows java though, it can always be explained that const in JS is identical to marking a local variable as final in Java.

More so than const, I was perplexed by the JS choice of the `let` keyword. Are there any other languages that use let for declarations that can be reassigned? Did BASIC allow lets to be reassigned? Can’t remember...

Post reply on HN