1. Array.prototype.includes – Array method includes
The includes()
method returns a Boolean value (true
or false
) based on whether an array contains a specific value or not. The array method includes has the following signature:
valueToFind
The value to search for. When comparing strings and characters,
includes()
is case-sensitive.
fromIndex
| Optional
Optional parameter, default value is 0. This is the position in the array from where search starts. If
fromIndex < 0
, search starts atarray.length + fromIndex
.
Return Value
– Boolean (true
or false
)
This method returns
true
if the value is found within the array, otherwise returnsfalse
.
Code Snippets
2. Exponentiation Operator (x**y)
The exponentiation operator **
is an ECMAScript proposal by Rick Waldron and available in ES7. This is an infix operator for exponentiation which produces the same result as Math.pow()
.
Code Snippets
Let us look into a few more test cases
In special cases, say you want to find the result of
-4 ** 3
, you may end up gettingSyntaxError
if you tryconsole.log(-4 ** 3);
. Let us look into the below example: