Easy learning with example program codes

typescript variable declaration

Variable is the name of reserved memory location. It means when we declare a variable some part of memory is reserved.

Rules for declaring a TypeScript variable:

  1. TypeScript variable name must begin with a letter, underscore, or dollar sign.
  2. TypeScript variable names are case sensitive.
  3. TypeScript reserved keywords like abstract, boolean etc can’t be used as TypeScript variable name.


Variable Declaration in TypeScript

TypeScript provides the following 4 ways to declare a variable. Common syntax for a variable declaration is to include a colon (:) after the variable name which followed by its type. We can use var or let keyword to declare a variable.

  1. Declare a variable with type and value.

    By using var keyword:

    var variableName:data_type = value;

    By using let keyword:

    let variableName:data_type = value;


  2. Declare a variable with type but no value. Variable’s value will be set to undefined by default.

    By using var keyword:

    var variableName:data_type;

    By using let keyword:

    let variableName:data_type;

  3. Declare a variable with value but no type. Variable’s type will be set to any by default.

    By using var keyword:

    var variableName = value;

    By using let keyword:

    let variableName = value;

  4. Declare a variable without type and value. Variable’s type will be set to any and value will be set to undefined by default.

    By using var keyword:

    var variableName;

    By using let keyword:

    let variableName;


TypeScript Tutorial

TypeScript Overview.
Typescript vs Javascript.
Typescript let vs var.
TypeScript Hello World.
Typescript Data Types.
Typescript Variable Declaration.
TypeScript operators list.
TypeScript Arithmetic Operators.
TypeScript Comparison Operators.
TypeScript Bitwise Operators.
Typescript Logical Operators.
TypeScript Assignment Operators.
Typescript Conditional Operator.
Typescript String Operator.
Typescript typeof Operator.
TypeScript control statements.
TypeScript Switch Statement.
TypeScript for loop.
TypeScript for in loop.
TypeScript while loop.
TypeScript do while loop.
Typescript for loop break.
TypeScript for loop continue.
Typescript function.
Typescript returning function.
Typescript parameterized function.
Typescript function optional parameter.
Typescript rest parameters.
Typescript default parameters.
Typescript anonymous function.
Typescript function constructor.
Typescript Arrow/Lambda function.
Typescript function overloading.
TypeScript number object.
TypeScript string object.
TypeScript boolean object.
TypeScript date object.
TypeScript math object.
TypeScript array object.
TypeScript tuples.
TypeScript union type.
TypeScript interface.
TypeScript interface inheritance.
TypeScript interface multiple inheritance.
TypeScript class.
Typescript class inheritance.
Typescript class interface.
TypeScript abstract class.
TypeScript object.
TypeScript duck typing.
TypeScript NameSpace.
TypeScript Multi-file namespaces.
TypeScript module.
TypeScript ambient module.

Copyright © 2019 CodesJava Protection Status SiteMap Reference: Java Wiki