- ES6 - Discussion
- ES6 - Useful Resources
- ES6 - Quick Guide
- ES9 - New Features
- ES8 - New Features
- ES7 - New Features
- ES6 - Browsers
- ES6 - Image Map
- ES6 - Debugging
- ES6 - Multimedia
- ES6 - Animation
- ES6 - Validations
- ES6 - Proxy API
- ES6 - Reflect API
- ES6 - Object Extensions
- ES6 - Error Handling
- ES6 - Modules
- ES6 - Promises
- ES6 - Maps And Sets
- ES6 - Classes
- ES6 - Collections
- ES6 - Iterator
- ES6 - HTML DOM
- ES6 - RegExp
- ES6 - Math
- ES6 - Date
- ES6 - Arrays
- ES6 - New String Methods
- ES6 - Symbol
- ES6 - Strings
- ES6 - Boolean
- ES6 - Number
- ES6 - Objects
- ES6 - Page Printing
- ES6 - Void Keyword
- ES6 - Dialog Boxes
- ES6 - Page Redirect
- ES6 - Cookies
- ES6 - Events
- ES6 - Functions
- ES6 - Loops
- ES6 - Decision Making
- ES6 - Operators
- ES6 - Variables
- ES6 - Syntax
- ES6 - Environment
- ES6 - Overview
- ES6 - Home
Selected Reading
- Who is Who
- Computer Glossary
- HR Interview Questions
- Effective Resume Writing
- Questions and Answers
- UPSC IAS Exams Notes
ES7 - New Features
This chapter provides knowledge about the new features in ES7.
Exponentiation Operator
ES7 introduces a new mathematical operator called exponentiation operator. This operator is similar to using Math.pow() method. Exponentiation operator is represented by a double asterisk **. The operator can be used only with numeric values. The syntax for using the exponentiation operator is given below −
Syntax
The syntax for the exponentiation operator is mentioned below −
base_value ** exponent_value
Example
The following example calculates the exponent of a number using the Math.pow() method and the exponentiation operator.
<script> let base = 2 let exponent = 3 console.log( using Math.pow() ,Math.pow(base,exponent)) console.log( using exponentiation operator ,base**exponent) </script>
The output of the above snippet is as given below −
using Math.pow() 8 using exponentiation operator 8
Array Includes
The Array.includes() method introduced in ES7 helps to check if an element is available in an array. Prior to ES7, the indexof() method of the Array class could be used to verify if a value exists in an array . The indexof() returns the index of the first occurrence of element in the array if the data is found ,else returns -1 if the data doesn t exist.
The Array.includes() method accepts a parameter, checks if the value passed as parameter exists in the array. This method returns true if the value is found, else returns false if the value doesn t exist. The syntax for using the Array.includes() method is given below −
Syntax
Array.includes(value)
OR
Array.includes(value,start_index)
The second syntax checks if the value exists from the index specified.
Example
The following example declares an array marks and uses the Array.includes() method to verify if a value is present in the array.
<script> let marks = [50,60,70,80] //check if 50 is included in array if(marks.includes(50)){ console.log( found element in array ) }else{ console.log( could not find element ) } // check if 50 is found from index 1 if(marks.includes(50,1)){ //search from index 1 console.log( found element in array ) }else{ console.log( could not find element ) } //check Not a Number(NaN) in an array console.log([NaN].includes(NaN)) //create an object array let user1 = {name: kannan }, user2 = {name: varun }, user3={name: prijin } let users = [user1,user2] //check object is available in array console.log(users.includes(user1)) console.log(users.includes(user3)) </script>
The output of the above code will be as stated below −
found element in array could not find element true true falseAdvertisements