Tech
News
Videos
Forums
Jobs
Books
Events
More
Interviews
Live
Learn
Training
Career
Members
Blogs
Challenges
Certification
Contribute
Article
Blog
Video
Ebook
Interview Question
Collapse
Feed
Dashboard
Wallet
Learn
Achievements
Network
Refer
Rewards
SharpGPT
Premium
Contribute
Article
Blog
Video
Ebook
Interview Question
Register
Login
Voice of a Developer: JavaScript ECMAScript 6 Features v2 - Part Twenty
WhatsApp
Guest User
4y
5.7k
0
2
100
Article
Introduction
JavaScript is a language of the Web. This series of articles will talk about my observations learned during my decade of software development experience with
JavaScript
.
Before moving further let us look at the previous articles of the series:
Voice of a Developer: JavaScript Data Types - Part One
Voice of a Developer: JavaScript Objects - Part Two
Voice of a Developer: JavaScript Engines - Part Three
Voice of a Developer: JavaScript Common Mistakes - Part Four
Voice of a Developer: Editors - Part Five
Voice of a Developer: VSCode - Part Six
Voice of a Developer: Debugging Capabilities of VSCode - Part Seven
Voice of a Developer: JavaScript OOP - Part Eight
Voice of a Developer:
JavaScript Useful Reserved Keywords - Part Nine
Voice of a Developer:
JavaScript Functions - Part Te
n
Voice of a Developer: JavaScript Functions Invocations - Part Eleven
Voice of a Developer: JavaScript Anonymous Functions - Part Twelve
Voice of a Developer: JavaScript Pure And Impure Function - Part Thirteen
Voice of a Developer: JavaScript Closures - Part Fourteen
Voice of a Developer: JavaScript Currying - Part Fifteen
Voice of a Developer: JavaScript Chaining - Part Sixteen
Voice of a Developer: JavaScript Array Methods - Part Seventeen
Voice of a Developer: JavaScript ECMAScript 6 - Part Eighteen
Voice of a Developer: JavaScript ECMAScript 6 Features v1 - Part Nineteen
In the last article, we learned about ECMAScript 6 features and now we will learn some more cool features.
Default values
We can add default values to function expressions. In ES5, the default value is undefined if the value is not passed via argument. Example ES5.
function
coordinates(x, y)
{
console.log(x);
console.log(y);
}
coordinates(10);
// 10 undefined
In ES6 we will change it to,
function
coordinates(x=10, y=20)
{
console.log(x);
console.log(y);
}
coordinates(10);
//10 20
Modules
This is the feature I like the most! We need to define each module in a file then export keyword to export. On the receiving side, we use import keyword to import. This modular approach is a really good solution for code reusability and abstraction.
Modules are designed around the export & import keywords.
Classes
This is a favorite keyword of OOPS developers but JavaScript is prototypal based and function is a first-class citizen in JavaScript. Introducing classes in ES6 is debatable and many people have notion that it is not in favor of JavaScript prototypal nature.
Leaving aside, we can understand what lies in this feature.
Like OOPS programming languages, classes in ES6 are revolving around class & constructor. Example,
class
Automobile
{
constructor(type)
{
this
.type =
'bike'
;
this
.engine =
'150 CC'
;
}
getEngine()
{
return
this
.engine;
}
}
var
vehicle =
new
Automobile(
'Honda'
);
console.log(vehicle.getEngine());
// 150 CC
Inheritance
Use extends keyword for an inheritance to inherit from the base class. Example
class
LogView
extends
View
{
render()
{
var
compiled =
super
.render();
console.log(compiled);
}
}
class
LogView
extends
View {}
Multi-line Strings
It’s a sugar syntax to cut long
var
s =
'hello '
+
'world'
;
console.log(s);
Summary
You can try these awesome features of ES6. Please share comments/ feedback.
ECMAScript 6 Features v2
JavaScript
JavaScript ECMAScript
Up Next
Ebook Download
View all
JavaScript Interview Q & A
Read by 882 people
Download Now!
Learn
View all
Membership not found