Let’s delve into hoisting in JavaScript! During compilation, microseconds before code is executed, variable and function declarations are “hoisted” i.e. they are added to memory inside a data structure called “lexical environment”. The official ES6 documentation describes the lexical environment as: “Lexical Environment is a specification type used to define the association of Identifiers to specific variables and functions based upon the lexical nesting structure
Scope in JavaScript & the 4 different types scope – Part 1
The word “scope” itself means “extent “or “range” to which a subject matter is limited to. In context to coding this means, that whether you can use a variable or not, is determined by where it is declared in your code. There are 4 types of scope in a JavaScript document, for example script.js 1. Global scope Inside a JavaScript document, global scope is the
ECMAScript and JavaScript – don’t get confused !
ECMA which is short for European Computer Manufacturer’s Association, is an international organization that creates standards for technologies. One of these standards is called “ECMA-262”. ECMA-262 is the standard for creating a general purpose scripting language. This standard is commonly called ECMAScript specification. This specification contains rules and guidelines for creating a scripting language. JavaScript which is a client-side scripting language is one of the
Functions as objects
In JavaScript functions are a type of object known as function object. You can work with function objects as though they were objects. Functions may be assigned to objects, passed in as arguments to other functions, returned from other functions. Additionally a function can be passed into an array. And this gets me to earlier in my articles when I’ve stated “almost everything in JavaScript
Getters & Setters in JavaScript – part 3
Setters in JavaScript. Check out parts 1 and 2 Setters in JavaScript There are three ways you can use setters:1. Default method syntax2. get keyword3. Object.defineProperty() method We will now discuss the above three in detail. 1. Default method syntax The default method syntax can also be used for setters. Setters will set the property of theobject to the value passed into the setter method.
Getters & Setters in JavaScript – part 2
carrying on from part 1 .. Getters in JavaScript Getters are functions that retrieve a value from static properties from an external source. You can only access properties and cannot access methods as they are functions of an object or class and are not static.There are three ways you can use getters and setters:1. Default method syntax2. get keyword3. Object.defineProperty() method We will now discuss
Classes in JavaScript – a newbie friendly introduction
Classes In object-oriented programming, class types are templates for creating objects. As we justlearned that in prototypal inheritance, objects inherit properties and methods from aprototype. Classes build upon prototypal inheritance. Classes were introduced in ES6 tomimic the class data type found in Java and other object-oriented programming languages. Till now developers used constructor functions to mimic object-oriented design patterns.JavaScript does not have the class type,
Setters and Getters in JavaScript – part 1
Accessors: Getters and Setters This is part 1 of a brief introduction to getters and setters in JavaScript. Getters and Setters are ES5 features. Objects have two types of properties: Static data property Accessor property So far we have come across static data properties in the objects that we have been making. For example: let blackLivesMatter = { status: true, usecase: ‘daily’ } In this
The break and continue statements in JavaScript
Break and continue statements The break statement is used to exit a loop completely once a condition has been met, or after x number of iterations. As such it is commonly used within an if conditional block. Take as an example the following code: for (let i = 0; i <= 5; i++){ console.log(i); } This will print out the value of variable i from
Deep & shallow copying in JavaScript – part 3
Copying objects with deep copy The JSON.stringify and JSON.parse methods can be used to deep copy an object. In a deep copy, the source and target objects have different memory addresses and are not connected at all. The JSON.stringify() method will take a JavaScript object as an argument and transform it into a string. Then the JSON.parse() method will parse the JavaScript string and return
- 1
- 2
- 3
- …
- 5
- Next Page »