Author Archives: Help_adm

JavaScript Style Guide

Always use the same coding conventions for all your JavaScript projects. JavaScript Coding Conventions Coding conventions are style guidelines for programming. They typically cover: Naming and declaration rules for variables and functions. Rules for the use of white space, indentation, and comments. Programming practices and principles Coding conventions secure quality: Improves code readability Make code maintenance easier… Read More »

JavaScript Debugging

Errors can (will) happen, every time you write some new computer code. Code Debugging Programming code might contain syntax errors, or logical errors. Many of these errors are difficult to diagnose. Often, when programming code contains errors, nothing will happen. There are no error messages, and you will get no indications where to search for… Read More »

JavaScript JSON

JSON is a format for storing and transporting data. JSON is often used when data is sent from a server to a web page. What is JSON? JSON stands for JavaScript Object Notation JSON is a lightweight data interchange format JSON is language independent * JSON is “self-describing” and easy to understand * The JSON syntax is derived from… Read More »

JavaScript Modules

Modules JavaScript modules allow you to break up your code into separate files. This makes it easier to maintain the code-base. JavaScript modules rely on the import and export statements. Export You can export a function or variable from any file. Let us create a file named person.js, and fill it with the things we want to export. There are… Read More »

JavaScript Classes

ECMAScript 2015, also known as ES6, introduced JavaScript Classes. JavaScript Classes are templates for JavaScript Objects. JavaScript Class Syntax Use the keyword class to create a class. Always add a method named constructor(): Syntax class ClassName {  constructor() { … }} Example class Car {  constructor(name, year) {    this.name = name;    this.year = year;  }} The example above creates a class named “Car”. The class… Read More »

JavaScript Arrow Function

Arrow functions were introduced in ES6. Arrow functions allow us to write shorter function syntax: Example: <!DOCTYPE html> <html> <body> <h2>JavaScript Arrow Function</h2> <p>This example shows the syntax of an Arrow Function, and how to use it.</p> <p id=”demo”></p> <script> let myFunction = (a, b) => a * b; document.getElementById(“demo”).innerHTML = myFunction(4, 5); </script> </body>… Read More »

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 »