Preview ES6 Tutorial (PDF Version)
Total Page:16
File Type:pdf, Size:1020Kb
ES6 ES6 About the Tutorial European Computer Manufacturers Association (ECMAScript) or (ES) is a standard for scripting languages like JavaScript, ActionScript and JScript. It was initially created to standardize JavaScript, which is the most popular implementation of ECMAScript. This tutorial adopts a simple and practical approach through JavaScript to describe the new features in ECMAScript 2015 (ES6), ECMAScript 2016 (ES7), ECMAScript 2017(ES8) and ECMAScript 2018 (ES9). Audience This tutorial is designed for the stemplate oftware programmers who have already worked with JavaScript and wishes to gain in-depth knowledge about the ECMAScript. The tutorial will give you enough understanding on the functionalities of ECMAScript and also about ES6, ES7, ES8 and ES9. Prerequisites An understanding of JavaScript programming concepts is necessary to gain maximum knowledge from this tutorial. Disclaimer & Copyright Copyright 2019 by Tutorials Point (I) Pvt. Ltd. All the content and graphics published in this e-book are the property of Tutorials Point (I) Pvt. Ltd. The user of this e-book is prohibited to reuse, retain, copy, distribute or republish any contents or a part of contents of this e-book in any manner without written consent of the publisher. We strive to update the contents of our website and tutorials as timely and as precisely as possible, however, the contents may contain inaccuracies or errors. Tutorials Point (I) Pvt. Ltd. provides no guarantee regarding the accuracy, timeliness or completeness of our website or its contents including this tutorial. If you discover any errors on our website or in this tutorial, please notify us at [email protected]. i ES6 Table of Contents About the Tutorial .................................................................................................................................... i Audience .................................................................................................................................................. i Prerequisites ............................................................................................................................................ i Disclaimer & Copyright ............................................................................................................................. i Table of Contents .................................................................................................................................... ii 1. ES6 − OVERVIEW ................................................................................................................. 1 JavaScript ................................................................................................................................................ 1 ECMAScript Versions ............................................................................................................................... 1 2. ES6 − ENVIRONMENT .......................................................................................................... 3 Local Environment Setup......................................................................................................................... 3 Installation on Windows ......................................................................................................................... 3 Installation on Mac OS X ......................................................................................................................... 4 Installation on Linux ................................................................................................................................ 5 Integrated Development Environment (IDE) Support .............................................................................. 5 Visual Studio Code .................................................................................................................................. 5 Brackets .................................................................................................................................................. 8 3. ES6 − SYNTAX .................................................................................................................... 11 Whitespace and Line Breaks .................................................................................................................. 12 Comments in JavaScript ........................................................................................................................ 12 Your First JavaScript Code ..................................................................................................................... 13 Executing the Code ................................................................................................................................ 13 Node.js and JS/ES6 ................................................................................................................................ 14 The Strict Mode ..................................................................................................................................... 14 ES6 and Hoisting .................................................................................................................................... 15 ii ES6 4. ES6 − VARIABLES ............................................................................................................... 16 Type Syntax ........................................................................................................................................... 16 JavaScript and Dynamic Typing ............................................................................................................. 17 JavaScriptVariable Scope ....................................................................................................................... 17 The Let and Block Scope ........................................................................................................................ 18 let and block level safety ....................................................................................................................... 19 let and multiple blocks .......................................................................................................................... 19 The const ............................................................................................................................................... 20 Constants are Immutable ...................................................................................................................... 21 const and arrays .................................................................................................................................... 21 The var keyword ................................................................................................................................... 22 var and hoisting .................................................................................................................................... 22 var and block scope ............................................................................................................................... 23 var and block level safety ...................................................................................................................... 23 5. ES6 − OPERATORS ............................................................................................................. 25 Arithmetic Operators ............................................................................................................................ 25 Relational Operators ............................................................................................................................. 27 Logical Operators .................................................................................................................................. 28 Bitwise Operators ................................................................................................................................. 29 Assignment Operators........................................................................................................................... 31 Miscellaneous Operators ...................................................................................................................... 32 6. ES6 − DECISION MAKING ................................................................................................... 37 The if Statement.................................................................................................................................... 37 The if…else Statement ........................................................................................................................... 39 The else…if Ladder ................................................................................................................................ 40 The switch…case Statement .................................................................................................................. 41 iii ES6 7. ES6 − LOOPS ...................................................................................................................... 45 Definite Loop......................................................................................................................................... 45 Indefinite Loop ...................................................................................................................................... 48 The Loop Control