JavaScript ES6
The let keyword
The let keyword was introduced in ES6 as a new way of declaring variables in JavaScript. It provides block-level scoping, which means that variables declared with let can only be accessed within the block in which they were declared.
The const keyword
The const keyword was introduced in ES6 as a new way to declare constants in JavaScript. Constants are similar to variables, but once defined, their value cannot be changed.
Arrow Functions
Arrow functions were introduced in ES6 as a shorthand syntax for writing functions in JavaScript. They provide a more concise and readable way to write functions, especially for simple one-line functions.
The ... Operator
The ... operator, also known as the spread syntax, was introduced in ES6 as a way to spread the elements of one iterable (like an array) into another iterable (like a function call).
For/of loop
The for...of loop was introduced in ES6 as a new way to loop over iterable objects (such as arrays, strings, and maps) in JavaScript. This provides a cleaner and more readable syntax than the traditional for loop.
Map Objects
A Map object in JavaScript is a collection of key-value pairs, similar to an object. However, Map objects can have any type of value as a key (not just strings or symbols, like objects), and they maintain the order of their elements (unlike objects).
Set Objects
A set object in JavaScript is a collection of unique values, which can be of any type. Unlike arrays, Set objects do not allow duplicates, so each value in the collection can appear only once.
JavaScript Classes
Classes were introduced in ES6 as a new way to define objects and their behavior in JavaScript. They provide a more familiar and structured syntax for creating objects that share the same properties and methods.
JavaScript Promises
Promises were introduced in ES6 as a way to handle asynchronous operations in JavaScript. They provide a cleaner and more structured way to handle callbacks and avoid callback hell. A promise is an object that represents a value that may not yet be available, but will be resolved (or deallocated) at some point in the future. Promises have three statuses: Pending, Resolved, or Rejected. Once a promise is resolved or discarded, it cannot be changed.
JavaScript Symbol
Symbol is a new primitive data type introduced in ES6. It is a unique identifier that can be used as a property key across objects. Symbols are guaranteed to be unique, even if their description is the same.
Default Parameters
Default parameters were introduced in ES6 as a way to provide default values for function parameters. If a function is called without passing the value of a parameter that has a default value, the default value will be used instead.
Function Rest Parameter
The rest parameter syntax allows a function to accept any number of arguments in the form of an array. The rest of the parameters are denoted by using three dots before the parameter name, as in: ...args.
String.includes()
The String.includes() is a String method introduced in ES6. It is used to determine whether a string contains another string, and returns a boolean value indicating whether the search string was found in the original string.
String.startsWith()
The startWith() method is a String method introduced in ES6. It is used to determine whether a string begins with another string, and returns a Boolean value indicating whether the search string was found at the beginning of the original string
String.endsWith()
endsWith() method is a String method introduced in ES6. It is used to determine whether a string ends with another string, and returns a Boolean value indicating whether the search string was found at the end of the original string.
Array.from()
Array.from() method is a static method introduced in ES6. It creates a new, shallowly-copied Array instance from an array-like or iterable object. The method takes two arguments: the first is the array-like or iterable object to be converted, and the second is an optional map function that can be used to map the values before adding them to the new array.
Array keys()
The keys() method is an array method introduced in ES6. It returns a new ArrayIterator object containing the keys of each index in the array
Array find()
find() method is an array method introduced in ES6. It is used to retrieve the value of the first element in an array that satisfies a condition. The method returns undefined if no element satisfies the condition. The find() method takes a callback function as its argument, which should return a boolean value. The method will return the first element that satisfies the condition.
Array findIndex()
findIndex() method is an array method introduced in ES6. It is used to retrieve the index of the first element in an array that satisfies a given condition. The method returns -1 if no element satisfies the condition. The findIndex() method takes a callback function as its argument, which should return a boolean value. The method will return the index of the first element that satisfies the condition.
New Math Methods
1. Math.trunc()
This method returns the integer part of a number by removing any fractional digits.
2. Math.sign()
This method returns the sign of a number, indicating whether the number is positive, negative, or zero. It returns 1 for positive numbers, -1 for negative numbers, and 0 for zero.
3. Math.cbrt()
This method returns the cube root of a number.
4. Math.log10()
This method returns the base 10 logarithm of a number.
5. Math.log2()
This method returns the base 2 logarithm of a number.
New Number Properties
1. Number.EPSILON
This property represents the smallest difference between two representable numbers. This is useful when comparing floating-point numbers for equality.
2. Number.MAX_SAFE_INTEGER
This property represents the maximum integer value that can be safely represented in JavaScript, which is 2^53 - 1.
New Number Methods
ES6 introduced several new methods to the Number object:
1. Number.isInteger()
This method determines whether the given value is an integer or not. Returns true if the value is an integer, otherwise false.
2. Number.isSafeInteger()
This method determines whether the given value is a safe integer or not. A safe integer is an integer that can be represented exactly as a number value. Returns true if the value is a safe integer, otherwise it returns false.
New Global Methods
ES6 introduced several new global methods, meaning they are not part of a specific object, but can be called directly from anywhere in the code. Here are some new global methods:
1. Number.isFinite()
This method determines whether the given value is a finite number or not. Returns true if the value is a finite number, otherwise it returns false.
2. Number.isNaN()
This method determines whether the given value is NaN or not. It returns true if the value is NaN, otherwise it returns false.
Object entries
Object.entries() is a method introduced in ES2017 (ES8) that returns an array of a given object's own enumerable property [key, value] pairs. It basically allows you to turn an object into an array of arrays, where each internal array contains two items: the key and the value of a property. The Object.entries() method is a new method introduced in ECMAScript 2017 (ES8) that returns an array of a given object's own enumerable property [key, value] pairs.
JavaScript Modules
JavaScript modules are a way of organising code into independent, reusable components. They are an important feature of ECMAScript 6 (ES6), which introduced a standardised module syntax for JavaScript. Modules allow developers to break down their code into smaller, more manageable pieces, which can then be imported and used in other parts of the codebase.
There are two types of JavaScript modules: built-in modules and user-defined modules.
- Built-in modules are provided by the JavaScript environment and include modules such as maths and date.
- User-defined modules are created by developers and can be shared and imported across different parts of the codebase.
ES6 modules use the import and export keywords to define and use modules. The export keyword is used to mark a function, variable, or object as public, making it available for use in other parts of the codebase. The import keyword is used to bring one module into another module.