Author: admin
-
Differences Between var and let
#1: Variable scopes The var variables belong to the global scope when you define them outside a function. For example: var counter;Code language: JavaScript (javascript) In this example, the counter is a global variable. It means that the counter variable is accessible by any function. When you declare a variable inside a function using the var keyword, the scope of the variable is…
-
Declaring Constants in ES6
ES6 provides a new way of declaring a constant by using the const keyword. The const keyword creates a read-only reference to a value. const CONSTANT_NAME = value;Code language: JavaScript (javascript) By convention, the constant identifiers are in uppercase. Like the let keyword, the const keyword declares blocked-scope variables. However, the block-scoped variables declared by the const keyword can’t be reassigned. The variables declared…
-
Introduction to the JavaScript let keyword
In ES5, when you declare a variable using the var keyword, the scope of the variable is either global or local. If you declare a variable outside of a function, the scope of the variable is global. When you declare a variable inside a function, the scope of the variable is local. ES6 provides a new way of declaring…
-
Classes
TypeScript is object oriented JavaScript. TypeScript supports object-oriented programming features like classes, interfaces, etc. A class in terms of OOP is a blueprint for creating objects. A class encapsulates data for the object. Typescript gives built in support for this concept called class. JavaScript ES5 or earlier didn’t support classes. Typescript gets this feature from…
-
Interfaces
An interface is a syntactical contract that an entity should conform to. In other words, an interface defines the syntax that any entity must adhere to. Interfaces define properties, methods, and events, which are the members of the interface. Interfaces contain only the declaration of the members. It is the responsibility of the deriving class…
-
Union
TypeScript 1.4 gives programs the ability to combine one or two types. Union types are a powerful way to express a value that can be one of the several types. Two or more data types are combined using the pipe symbol (|) to denote a Union Type. In other words, a union type is written…
-
Tuples
At times, there might be a need to store a collection of values of varied types. Arrays will not serve this purpose. TypeScript gives us a data type called tuple that helps to achieve such a purpose. It represents a heterogeneous collection of values. In other words, tuples enable storing multiple fields of different types.…
-
Arrays
The use of variables to store values poses the following limitations − TypeScript introduces the concept of arrays to tackle the same. An array is a homogenous collection of values. To simplify, an array is a collection of values of the same data type. It is a user defined type. Features of an Array Here…
-
Strings
The String object lets you work with a series of characters. It wraps the string primitive data type with a number of helper methods. Syntax var var_name = new String(string); A list of the methods available in String object along with their description is given below − S.No. Property & Description 1. ConstructorReturns a reference…
-
Numbers
TypeScript like JavaScript supports numeric values as Number objects. A number object converts numeric literal to an instance of the number class. The Number class acts as a wrapper and enables manipulation of numeric literals as they were objects. Syntax In case a non-numeric argument is passed as an argument to the Number’s constructor, it…