What are variables in Typescript? How to create a variable in Typescript?

devquora
devquora

Posted On: Feb 22, 2018

 

A variable is a named space in the memory which stores a particular value. While declaring a variable in Typescript, certain rules should be followed like-
  1. A variable name should contain alphabets and numeric digits.
  2. It cannot contain spaces and special characters except underscore (_) and dollar ($) sign.
  3. A variable name cannot begin with a digit.

You should always keep in mind, that a variable should be declared before being used. Variables in Typescript are declared by placing a “var” keyword prior to the variable name. A variable can be declared using 4 methods: –

  • Declare its type and value in one statement.Syntax- var variable_name:string = value;
  • Declare its type but no value.Syntax- var variable_name:string;
  • Declare its value but no type.Syntax- var variable_name = value;
  • Declare neither value nor type.Syntax- var variable_name;

    Related Questions

    Please Login or Register to leave a response.

    Related Questions

    Typescript Interview Questions

    What is Typescript?

    Typescript is a free and open-source programming language which is designed and developed by Microsoft. It was designed ..

    Typescript Interview Questions

    List some features of Typescript?

    Features of Typescript are:- Typescript can be compiled to all major versions of Javascript(ES3,ES5,ES6,ES7). Typescrip..

    Typescript Interview Questions

    List some benefits of using Typescript?

    Following are some benefits of using Typescript One of the biggest advantages of Typescript is its code completion and ..