SlideShare a Scribd company logo
Lecture 2: ES6/ES2015 and
Beyonds with the Best Practices

Kobkrit Viriyayudhakorn, Ph.D.
CEO of iApp Technology Limited.
kobkrit@gmail.com
http://www.kobkrit.com
What we will learn today?
• A bit on JavaScript History
• Learn how to program in the modern JavaScript
i.e., ECMAScript 2015 (Version 6) / ECMAScript 6 /
ES2015 / ES6 complied by BabelJS
• Program with the best practices (Airbnb coding
style) and style checking tools by ESLint
Short History
• Want to added support for Java applets more
accessible to non-Java programmers in Netscape.
• Developed by Brendan Eich of Netscape
• December 1995
• Mocha => LiveScript => JavaScript
• Popular!
• Microsoft release JScript
• NetScape submit to ECMA for standardize
ECMAScript
• Script-Language
Specification
• Standardized by Ecma
International in
ECMA-262 and ISO/IEC
16262, based on
JavaScript
• First Appeared June
1997, 19 year ago.
Significant Development
• V8 JavaScript engine (2008). To compete with Internet
Explorer on JavaScript benchmark, Google developed v8 that
can compile JavaScript to Native Machine code. It is very fast.
• NodeJS + NPM (2009): Using V8 to make server-side
JavaScript Web Application.
• MongoDB (2009): No SQL database based on V8 engine.
• React (2013): JavaScript Front-end Web framework for
creating Interactive UI.
• React-Native (2015): Enable to Mobile App Development
https://www.youtube.com/watch?v=8ybquJSjZHg
HomeBrew Installation
• Open Terminal (Click on Find icon on the top right
of the screen)
• Type “Terminal”
• Enter $ /usr/bin/ruby -e "$(curl -fsSL https://
raw.githubusercontent.com/Homebrew/install/
master/install)"
Install React-Native in Mac
for iOS Development.
React-Native-Cli Command
Atom IDE
https://atom.io/
Setup the Project
• Download atom IDE and install
• $ cd workingFolder
• $ react-native init l2es6
• $ cd l2es6
• $ react-native run-ios
• $ atom .
Making a new JS file
Right click on l2es6, Select New File, Type down a new file
with JS extension
Running JS Script
• Open Terminal (Open
Spotlight  , Type
Terminal)
• Change Directory to
working directory 

($ cd {working dir})
• $ node {filename.js}
Let’s Start with ES6
ES6 Basic
• /* Comment */
• // Comment
• console.log(‘print out’);
• Syntax mostly derived from C language
• if (true){}
• while (true){}
• do{…} while(true);
• for(init ; condition; incr) {}
Primitive Types
• Directly Store Value
• string
• number
• boolean
• null
• undefined
Primitive Type #1: String, Number, and Boolean
Primitive Type #2: Null, Undefined, and Reference by Value
Exercise 1
Complex Types
• Reference of its value
• object
• array
• function
Complex Type #1: Object & Array
Complex Type #2: Function and Pass by Reference
Exercise 2
Declaration 

(Var, Let and Const)
• Var, Let, Const = Making Variable Declaration
• Const = Constant Declaration, Can’t Reassign.
• Use with reference that never change.
• Block-Level Scope
• Safer (If reassignment happen, it will throw the
errors)
Declaration

(Var, Let and Const)
• Let = Variable Declaration, Can Reassign.
• Block-Level Scope
• Var = Variable Declaration, Can Reassign
• Global-Level Scope
• Old JavaScript
• Dangerous. Don’t use it.
Declaration #1: Global Scope, Block Scope and Constant
Declaration #2: General Use Case in For loop
Exercise 3
Functions
• Function in JavaScript are objects, which can use
as arguments.
• Function can be invoked.
Function #1: Declaration, Invocation
Function #2: ES6 Feature - Declaration
Exercise 4
Function #3: Anonymous Function
Function #4: Recursive
Function #5: Callback
Exercise 5
Function #6: Exceptions
Function #7: ES6 Feature - Rest Params (Spreads …),

Default Params
Function #8: ES6 Feature - Named Parameters
Exercise 6
Function’s Airbnb Style
Guides
Style Guide #1. Use function declarations instead of function
expressions.
Style Guide #2. Wrap immediately invoked function
expressions in parentheses.
Why? An immediately invoked function expression is a single unit -
wrapping both it, and its invocation parens, in parens, cleanly expresses
this.
Style Guide #3. Never declare a function in a non-function
block (if, while, etc.)
Style Guide #4. Never use arguments, use … instead.
Style Guide #5. Use parameter syntax rather than mutating
function arguments.
Style Guide #6. Avoid side effects with default parameters
Style Guide #7: Always put default parameters last.
Style Guide #8: Use spread operator … to call variadic
function.
Style Guide #8: Use Arrow Functions when passing an 

anonymous function.
Style Guide #9: Omit braces and use the implicit return, if the
function body consists of a single expressions.
Style Guide #10: If your function takes a single argument and
doesn’t use braces, omit the parentheses. Otherwise, always
include parentheses around arguments.
Object
• Object is a dictionary data structure.
• Map between Key => Value
Object #1: Declaration, Reference
Object #2: Assignment, Retrieval, Re-Assignment
Object #3: Deletion, Keys, Size, Loops
Exercise 7
• Complete the following code that can change digit
to reading word.



For example, 12.3 => “one two dot three”
Starting code
HomeWork 1
(1) Write down a function that sum every element in
array. E.g. sumArray([12,3,4,1,2,3]) = 25
HomeWork 2
(2) Write function that count word size case-insensitively.
Input: "Hello world hello hello earth earth" (Not limited to
these word, it can be any words)
Output: Object{hello : 3, world : 1, earth : 2 }
Q/A

More Related Content

PDF
[React Native Tutorial] Lecture 6: Component, Props, and Network
PDF
[React-Native Tutorial] Lecture 8: Midterm Exam Discussion, Feedback, and Ter...
PDF
React Native Firebase Realtime Database + Authentication
PDF
Lecture 3 - ES6 Script Advanced for React-Native
PDF
[React Native Tutorial] Lecture 5: Input and State
PDF
[React-Native Tutorial 10] Camera Roll / Gallery / Camera / Native Modules by...
PDF
React-Native Lecture 11: In App Storage
PDF
Lecture 12: React-Native Firebase Authentication
[React Native Tutorial] Lecture 6: Component, Props, and Network
[React-Native Tutorial] Lecture 8: Midterm Exam Discussion, Feedback, and Ter...
React Native Firebase Realtime Database + Authentication
Lecture 3 - ES6 Script Advanced for React-Native
[React Native Tutorial] Lecture 5: Input and State
[React-Native Tutorial 10] Camera Roll / Gallery / Camera / Native Modules by...
React-Native Lecture 11: In App Storage
Lecture 12: React-Native Firebase Authentication

What's hot (20)

PDF
Introduction to React Native & Rendering Charts / Graphs
PPTX
Patterns in JavaScript
PDF
Ryan Christiani I Heard React Was Good
PDF
An Overview of the React Ecosystem
PDF
Introduction to React Native & Redux
PDF
[React Native Tutorial] Lecture 7: Navigation - Scene Transition - ListView
PDF
[React-Native Tutorial] Map
PPTX
React Native: Introduction
PPTX
Selenium Training in Chennai Demo Part-2
PPTX
What are the components in React?
PPTX
Introduction to angular 2
PDF
From zero to hero with React Native!
PPTX
React js basics
PDF
Page Object Model and Implementation in Selenium
PDF
Angular 2 Essential Training
PDF
End to end testing Single Page Apps & APIs with Cucumber.js and Puppeteer (Em...
PDF
E2E testing Single Page Apps and APIs with Cucumber.js and Puppeteer
PPTX
Angular 2 + TypeScript = true. Let's Play!
PPTX
An afternoon with angular 2
Introduction to React Native & Rendering Charts / Graphs
Patterns in JavaScript
Ryan Christiani I Heard React Was Good
An Overview of the React Ecosystem
Introduction to React Native & Redux
[React Native Tutorial] Lecture 7: Navigation - Scene Transition - ListView
[React-Native Tutorial] Map
React Native: Introduction
Selenium Training in Chennai Demo Part-2
What are the components in React?
Introduction to angular 2
From zero to hero with React Native!
React js basics
Page Object Model and Implementation in Selenium
Angular 2 Essential Training
End to end testing Single Page Apps & APIs with Cucumber.js and Puppeteer (Em...
E2E testing Single Page Apps and APIs with Cucumber.js and Puppeteer
Angular 2 + TypeScript = true. Let's Play!
An afternoon with angular 2
Ad

Similar to Lecture 2: ES6 / ES2015 Slide (20)

PDF
JavaScript Good Practices
PDF
Complete JavaScript Notes: From Basics to Advanced Concepts.pdf
PDF
You Don t Know JS ES6 Beyond Kyle Simpson
PDF
JavaScript The Definitive Guide 7th Edition David Flanagan
PDF
Basics of JavaScript
PDF
React Native One Day
PPT
13665449.ppt
PDF
Intro to JavaScript - Thinkful LA, June 2017
PDF
React Native Evening
PDF
JavaScript: Core Part
PDF
JavaScript for impatient programmers.pdf
PPT
JavaScript - An Introduction
PDF
slides-students-C03.pdf
PDF
JavaScript Foundations Day1
PDF
Special Edition Using Javascript Mcfedries
PDF
You don't know js yet
PPT
Intermediate JavaScript
PPTX
Intro to Javascript
PPTX
Getting started with ES6
PPTX
Introduction to Client-Side Javascript
JavaScript Good Practices
Complete JavaScript Notes: From Basics to Advanced Concepts.pdf
You Don t Know JS ES6 Beyond Kyle Simpson
JavaScript The Definitive Guide 7th Edition David Flanagan
Basics of JavaScript
React Native One Day
13665449.ppt
Intro to JavaScript - Thinkful LA, June 2017
React Native Evening
JavaScript: Core Part
JavaScript for impatient programmers.pdf
JavaScript - An Introduction
slides-students-C03.pdf
JavaScript Foundations Day1
Special Edition Using Javascript Mcfedries
You don't know js yet
Intermediate JavaScript
Intro to Javascript
Getting started with ES6
Introduction to Client-Side Javascript
Ad

More from Kobkrit Viriyayudhakorn (20)

PDF
Thai E-Voting System
PPTX
Thai National ID Card OCR
PPTX
Chochae Robot - Thai voice communication extension pack for Service Robot
PDF
ศักยภาพของ AI สู่โอกาสใหม่แห่งการแข่งขันและความสำเร็จ (Thai AI updates in yea...
PDF
Thai Text processing by Transfer Learning using Transformer (Bert)
PDF
How Emoticon Affects Chatbot Users
PPTX
หัวใจของปัญญาประดิษฐ์ (Gradient Descent ทำงานอย่างไร)
PDF
Check Raka Chatbot Pitching Presentation
PPTX
[Lecture 3] AI and Deep Learning: Logistic Regression (Coding)
PPTX
[Lecture 4] AI and Deep Learning: Neural Network (Theory)
PPTX
[Lecture 2] AI and Deep Learning: Logistic Regression (Theory)
PDF
ITS488 Lecture 6: Music and Sound Effect & GVR Try out.
PDF
Unity Google VR Cardboard Deployment on iOS and Android
PDF
ITS488 Lecture 4: Google VR Cardboard Game Development: Basket Ball Game #2
PDF
Lecture 4: ITS488 Digital Content Creation with Unity - Game and VR Programming
PDF
Lecture 2: C# Programming for VR application in Unity
PDF
Lecture 1 Introduction to VR Programming
PDF
Thai Word Embedding with Tensorflow
PDF
สร้างซอฟต์แวร์อย่างไรให้โดนใจผู้คน (How to make software that people love)
PDF
Startup Pitching and Mobile App Startup
Thai E-Voting System
Thai National ID Card OCR
Chochae Robot - Thai voice communication extension pack for Service Robot
ศักยภาพของ AI สู่โอกาสใหม่แห่งการแข่งขันและความสำเร็จ (Thai AI updates in yea...
Thai Text processing by Transfer Learning using Transformer (Bert)
How Emoticon Affects Chatbot Users
หัวใจของปัญญาประดิษฐ์ (Gradient Descent ทำงานอย่างไร)
Check Raka Chatbot Pitching Presentation
[Lecture 3] AI and Deep Learning: Logistic Regression (Coding)
[Lecture 4] AI and Deep Learning: Neural Network (Theory)
[Lecture 2] AI and Deep Learning: Logistic Regression (Theory)
ITS488 Lecture 6: Music and Sound Effect & GVR Try out.
Unity Google VR Cardboard Deployment on iOS and Android
ITS488 Lecture 4: Google VR Cardboard Game Development: Basket Ball Game #2
Lecture 4: ITS488 Digital Content Creation with Unity - Game and VR Programming
Lecture 2: C# Programming for VR application in Unity
Lecture 1 Introduction to VR Programming
Thai Word Embedding with Tensorflow
สร้างซอฟต์แวร์อย่างไรให้โดนใจผู้คน (How to make software that people love)
Startup Pitching and Mobile App Startup

Lecture 2: ES6 / ES2015 Slide