DynamicPL/Javascript
-
Destructuring, Spread, Rest parameters, Default parameters, Maps and ArraysDynamicPL/Javascript 2019. 10. 24. 19:28
1. Overview There are several new features added in ES6 which are Destructing, Spread, Rest, Default parameter, and so on. 2. Description 2.1 Destructing // ES5 var john = ['John', 26]; //var name = john[0]; //var age = john[1]; // ES6 // assign each element to variable const [name, age] = ['John', 26]; console.log(name); console.log(age); const obj = { firstName: 'John', lastName: 'Smith' }; co..
-
Arrow functionDynamicPL/Javascript 2019. 10. 24. 17:43
1. Overview Arrow functions which are added in ES6 are so simple and share the surrounding this keyword. Unlike normal function, arrow functions don't get their own "this" keyword. 2. Description 2.1 Expression const years = [1990, 1965, 1982, 1937]; // ES5 var ages5 = years.map(function(el) { return 2016 - el; }); console.log(ages5); // ES6 // a lots less code let ages6 = years.map(el => 2016 -..
-
let, const, block scope, function scope and IIFEsDynamicPL/Javascript 2019. 10. 24. 15:05
1. Overview Variables declared with var in ES5 are function-scoped and Variables declared with let and const in ES6 are block-scoped. 2. Description 2.1 Function-scoped Variables, which declared var, are only accessible inside of a function, but not from the outside. And we would use a variable before the declaration, it would be an "undefined" cause of hoisting. function driversLicence5(passedT..
-
Bind, Call and ApplyDynamicPL/Javascript 2019. 10. 24. 02:18
1. Overview Functions are a special kind of object and also get a couple of special methods that they inherit from the function constructor object such as call, apply and bind methods. These methods allow us to call a function and set this variable manually. 2. Description var john = { name: 'John', age: 26, job: 'teacher', presentation: function(style, timeOfDay) { if (style === 'formal') { con..
-
First-Class Functions and IIFEDynamicPL/Javascript 2019. 10. 24. 00:31
1. Overview We can pass functions as arguments and return it and store it into variables because functions are always first-class functions in Javascript because they are effectively objects. 2. Description 2.1 Passing Functions as Arguments These functions are called "callback function" because they are functions that we pass into functions that will then call them later. var years = [1990, 196..
-
Primitives vs. ObjectsDynamicPL/Javascript 2019. 10. 24. 00:18
1. Overview Let's distinguish differences between primitives and objects 2. Description 2.1 Difference 2.1.1 Primitives Variables containing primitives actually hold that data inside of the variable itself. 2.1.2 Objectives Variables associated objects do not actually contain the object but instead, they contain a reference to the place in memory where the object is stored. That means these vari..
-
Classes and subclassesDynamicPL/Javascript 2019. 10. 23. 12:42
1. Overview Class is added in ES6 and doesn't add anything new to the language, but just synthetic sugar over the way we do prototypal inheritance in Javascript. Classes simply make it easier to implement inheritance and to create objects based on blueprints which are called function constructors in ES5. 2. Previous way to inherit methods var Person5 = function(name, yearOfBirth, job) { this.nam..
-
Promises, Promisification, Async, Await, and AjaxDynamicPL/Javascript 2019. 10. 23. 10:42
1. Overview The Promise object represents the eventual completion (or failure) of an asynchronous operation and its resulting value. But syntax to consume promise can still be quite confusing and difficult to manage. And so in ES8 or ES2017, something called Async/Await was introduced to JavaScript in order to make it a lot easier for developers to consume promises. 2. Motivation 2.1 Callback he..