The point about Spread and Rest is not correct, it should be the other way around.
Rest syntax looks exactly like spread syntax. In a way, rest syntax is the opposite of spread syntax. Spread syntax "expands" an array into its elements, while rest syntax collects multiple elements and "condenses" them into a single element
I was also surprised to see no example of function in the 'Hoisting' section. It is the one form of hoisting that I find very useful because it allows you to optimize the readability of the code.
Use it if you need to declare a variable globally and modify it in a function and the changed value to be available globally. Probably best to leave comments as well as this would be unusual behaviour. There are likely other ways to achieve your logic as well
Sort of. You should declare it globally BECAUSE you intend to modify it within a localised scope. This is how the js frameworks work. Vue is effectively a Global object which can have it's properties manipulated by the functions within it. but then we are getting into immutability and state management.
The point about Spread and Rest is not correct, it should be the other way around.
Source: MDN
Nice explication thank for sharing Khang!
Hello, these are some interesting comparisons.
I was kinda surprised to see no example of
spreadin the 'Spread vs rest' section. A few examples ofspread:I was also surprised to see no example of
functionin the 'Hoisting' section. It is the one form of hoisting that I find very useful because it allows you to optimize the readability of the code.An example that hopefully communicates how you can improve readability by relying on hoisting:
This helps the reader by obtaining an overview before diving into details.
Nice thank you!
When to use
var? Don't.Use it if you need to declare a variable globally and modify it in a function and the changed value to be available globally. Probably best to leave comments as well as this would be unusual behaviour. There are likely other ways to achieve your logic as well
Yes and moreover, it can be dangerous to create global variable in general since you can easily override it
Sort of. You should declare it globally BECAUSE you intend to modify it within a localised scope. This is how the js frameworks work. Vue is effectively a Global object which can have it's properties manipulated by the functions within it. but then we are getting into immutability and state management.
Thanks for this
A nice article as always, thoses basics concept should be used and known by all !