Javascript: ES6, Cross-browser testing, and error handling

In this article, I will try to give write down about three topics that are very interesting and I have also had so much fun while learning these topics.

1.ES6(ECMAScript 6 )

ECMAScript 2015 or ES2015 is a cool update to JavaScript. It is the first major update to the language since ES5 which was standardized in 2009. Therefore, ES2015 is often called ES6.

Some key features of ES6 are-

A.Syntax -

let (it is used to declare a block-scoped variables, variables value that might change)

const (to declare const variable)

B.arrow function-

const add=(num1,num2)=>{

return num1 +num2;

}

console.log(add);

C. Destructuring array-

function getNumbers() {

return [10, 20, 30, 40];

}

let [x, y, z] = getNumbers();

console.log(x); // 10

console.log(y); // 20

console.log(z); // 30

let [x, y ,…args] = getNumbers();

console.log(x); // 10

console.log(y); // 20

console.log(args); // [30, 400]

You can see now destructuring an array is pretty simple. As the variables in the array are also the index of an array. Besides the rest of the array, element can be copied to another variable by simply using (…variableName).

D.Map

This is one of the most interesting updates of ES6, it makes the iteration easier. We can map through arrays. For example, ‘flowers’ is an array of objects containing different types of flower’s data. Map iterates through the ‘flowers’ array and finds out every single flower data.

E. Array Extension

->find

let numbers = [1, 2, 3, 4, 5];

console.log(numbers.find(e => e % 2 == 0));//2

2.Cross Browser Testing

Cross-browser testing is basically checking or testing the functionality of a website in different browsers. The next logical question could be, why do we need cross-browser testing? The first and simple answer would be, what is wrong with our web application layout in different common browsers (eg. Chrome, Mozilla, Safari, etc). If we check the user market share of different browsers we can see a large number of users use these three browsers(Chrome, Safari, Mozilla Firefox) on their computer. Therefore as a developer or a web application development company must check their application on different platforms, so that the users can have a smooth experience otherwise there will be bugs in the website.

How can you perform cross-browser testing?

One way is, you can run your website in different browsers manually which is not recommended and time-consuming. There are online tools like (Browser stack, Sauce labs, etc)

3.Error Handling

If there could be errors in a specific method in your website and you don't want your website crashed because of that error. There are cool solutions for this. You can handle errors by using different methods. But here I am going to talk about Try catch block.

try {
//Try your code here, that could cause error
}
catch (exception e) {
//If there is an error, the error will be caught here
}
finally {
//You can close the method here
}

Note: New cool stuff will be added…

Enthusiastic web developer | Student | Filmmaker