Overview of JavaScript ES6 features
adrianmejia.com
Overview of JavaScript ES6 features
1–10 of 250 posts
Re: Overview of JavaScript ES6 features
#2const info = [1,2,3,4]
const newInfo = info.splice(2);
'info' has changed
Re: Overview of JavaScript ES6 features
#3Using const and `splice` breaks the rules: const info = [1,2,3,4] const newInfo = info.splice(2); 'info' has changed
If you know C/C++, the code 'const info = []' makes 'info' a constant pointer to a list not a pointer to a constant list.
If you want to stop a variable from being changed, use Object.freeze() - https://developer.mozilla.org/en/docs/Web/JavaScript/Referen...
Re: Overview of JavaScript ES6 features
#4Using const and `splice` breaks the rules: const info = [1,2,3,4] const newInfo = info.splice(2); 'info' has changed
Re: Overview of JavaScript ES6 features
#5Using const and `splice` breaks the rules: const info = [1,2,3,4] const newInfo = info.splice(2); 'info' has changed
const number = 1337;
number = 10; // fails
But objects/arrays are not immutable in js, so you can do this:
const person = { name: 'Dude' };
person.name = 'Dudette';
Which is perfectly valid. If you want full immutability, i recommend you check out https://facebook.github.io/immutable-js/, been running it in production, a real pleasure to work with.
Re: Overview of JavaScript ES6 features
#6Is it? Personally I'd say that was bad code. What so wrong with using the original objects?
Putting aside the need to variable swap once a year or so, all the other examples look really confusing to me and unclear what they're doing. The `Deep Matching` especially.
Re: Overview of JavaScript ES6 features
#7Re: Overview of JavaScript ES6 features
#8This is because of hoisting. Not quite right as described.
Re: Overview of JavaScript ES6 features
#9Ex:
Re: Overview of JavaScript ES6 features
#10Using const and `splice` breaks the rules: const info = [1,2,3,4] const newInfo = info.splice(2); 'info' has changed