ES6 is awesome. Why? It brings a new approach to code in Javascript. It has class and constructor so we can mimic OOP better. class Dog { constructor(name) { this._name = name; } get name() { return this._name; // returning a private variable _name } set name(newName) { let regex = new RegExp(‘^[a-zA-Z0-9.]*$’); if (regex.test(newName))…
Posts Tagged
object
What is “this” in Javascript?
What is “this” in Javascript – especially, when you use bind( ), arrow function and regular function? this refers to its closest object. Maya, you’re not making any sense! Wait, let me explain. If this is called in a global scope, then this refers to “window” object in a browser or “global” object in Node. function…
Object Literal in Javascript – How to Create (and Use) an Object and its Properties?
A JavaScript object literal is a comma-separated list of name-value pairs wrapped in curly braces. Object literals encapsulate data, enclosing it in a tidy package. comma , is needed at the end of property declaration. A trailing comma is a comma for your last property. There is no error generated for not putting a comma for…
Javascript (Var vs Let vs Const)
VAR Var is functioned-scoped and variables defined in the function CAN NOT be accessed from its outer function. But variables can be accessed from its inner function. Children-scoped variables can USE its parents variables. Parents can not use its children variables – because … well, yeah, children like to keep secrets 😀 Var is hoisted…