Category Archives: Java Script

The JavaScript this Keyword

Example: <!DOCTYPE html> <html> <body> <h1>The JavaScript <i>this</i> Keyword</h1> <p>In this example, <b>this</b> refers to the <b>person</b> object.</p> <p>Because <b>fullName</b> is a method of the person object.</p> <p id=”demo”></p> <script> // Create an object: const person = {  firstName: “John”,  lastName: “Doe”,  id: 5566,  fullName : function() {    return this.firstName + ” ” +… Read More »

JavaScript Use Strict

“use strict”; Defines that JavaScript code should be executed in “strict mode”. The “use strict” Directive The “use strict” directive was new in ECMAScript version 5. It is not a statement, but a literal expression, ignored by earlier versions of JavaScript. The purpose of “use strict” is to indicate that the code should be executed in “strict mode”. With strict… Read More »

JavaScript Hoisting

Hoisting is JavaScript’s default behavior of moving declarations to the top. JavaScript Declarations are Hoisted In JavaScript, a variable can be declared after it has been used. In other words; a variable can be used before it has been declared. Example 1 gives the same result as Example 2: Example 1: <!DOCTYPE html> <html> <body> <p id=”demo”></p>… Read More »

JavaScript Scope

Scope determines the accessibility (visibility) of variables. JavaScript has 3 types of scope: Block scope Function scope Global scope Block Scope Before ES6 (2015), JavaScript had only Global Scope and Function Scope. ES6 introduced two important new JavaScript keywords: let and const. These two keywords provide Block Scope in JavaScript. Variables declared inside a { } block cannot be accessed from outside the… Read More »

JavaScript Errors

Throw, and Try…Catch…Finally The try statement defines a code block to run (to try). The catch statement defines a code block to handle any error. The finally statement defines a code block to run regardless of the result. The throw statement defines a custom error. Errors Will Happen! When executing JavaScript code, different errors can occur. Errors can be coding errors made by… Read More »

JavaScript Regular Expressions

A regular expression is a sequence of characters that forms a search pattern. The search pattern can be used for text search and text replace operations. What Is a Regular Expression? A regular expression is a sequence of characters that forms a search pattern. When you search for data in a text, you can use this… Read More »

JavaScript Bitwise Operations

JavaScript Bitwise Operators Operator Name Description & AND Sets each bit to 1 if both bits are 1 | OR Sets each bit to 1 if one of two bits is 1 ^ XOR Sets each bit to 1 if only one of two bits is 1 ~ NOT Inverts all the bits << Zero… Read More »

JavaScript Type Conversion

Converting Strings to Numbers Converting Numbers to Strings Converting Dates to Numbers Converting Numbers to Dates Converting Booleans to Numbers Converting Numbers to Booleans JavaScript Type Conversion JavaScript variables can be converted to a new variable and another data type: By the use of a JavaScript function Automatically by JavaScript itself Converting Strings to Numbers The… Read More »

JavaScript typeof

In JavaScript there are 5 different data types that can contain values: string number boolean object function There are 6 types of objects: Object Date Array String Number Boolean And 2 data types that cannot contain values: null undefined The typeof Operator You can use the typeof operator to find the data type of a JavaScript variable.… Read More »

JavaScript Maps

A Map holds key-value pairs where the keys can be any datatype. A Map remembers the original insertion order of the keys. Essential Map Methods Method Description new Map() Creates a new Map set() Sets the value for a key in a Map get() Gets the value for a key in a Map delete() Removes… Read More »