Javascript the Old way and the New way

in #javascript6 years ago (edited)

Here is a write up on my learning process. I'm going to highlight the syntax differences between ES5 and ES6, this can easily help you to get the difference at a glance without needing to worry much. so let's dive in.

ES5(The old way)ES6(The new way)
Declaring Variables Eg:
var x = food
let x = food (used if you want to reassign the variable in future)
const y = juice (used when variables cannot be reassigned)
Concatenation Eg:
var favorite = silicon valley;
var info = 'My favorite series is ' + favorite
Using template literals:
var info = My favorite series is ${favorite} with `` covering it.
Extracting values from arrays Eg:
var value = [50, 80];

var x = value[0];
var y = value[1];

console.log(x, y);
prints: 50 80
Using distructuring:
const value= [50, 80];

const [x, y] = value;

console.log(x, y);
prints: 50 80
Iterations Eg:
const num= [1, 2, 3, 4, 5];
for (let i = 0; i < num.length; i++) {
console.log(num[i]);
}
OR
for (const index in num) {
console.log(num[index]);
}
const nums= [1, 2, 3, 4, 5];
for (const num of nums) {
console.log(num);
}
Arrow functions Eg:
const vehicles = cars.filter(function(car) {
return car.length > 9;
});
const vehicles = cars.filter(car => car.length > 9);
Sort:  

@ifyokoh, I gave you an upvote on your first post! Please give me a follow and I will give you a follow in return!

Please also take a moment to read this post regarding bad behavior on Steemit.

Congratulations @ifyokoh! You received a personal award!

Happy Birthday! - You are on the Steem blockchain for 1 year!

You can view your badges on your Steem Board and compare to others on the Steem Ranking

Do not miss the last post from @steemitboard:

3 years on Steem - The distribution of commemorative badges has begun!
Happy Birthday! The Steem blockchain is running for 3 years.
Vote for @Steemitboard as a witness to get one more award and increased upvotes!

Coin Marketplace

STEEM 0.19
TRX 0.18
JST 0.034
BTC 89118.52
ETH 3131.33
USDT 1.00
SBD 2.76