Languages
[Edit]
EN

TypeScript - primitive types

3 points
Created by:
evangeline
390

In TypeScript there are available following primitive types.

1. number type example

let a = 123;
let b = 3.14;
let c : number = 123;
let d : number = 3.14;

console.log(`a=${a} b=${b} c=${c} d=${d}`);

Output:

a=123 b=3.14 c=123 d=3.14

2. string type example

let a = 'Hello world!';
let b : string = 'Hello world!';

console.log(`a='${a}' b='${b}'`);

Output:

a='Hello world!' b='Hello world!'

3. boolean type example

let a = true;
let b : boolean = false;

console.log(`a=${a} b=${b}`);

Output:

a=true b=false

4. void type example

function doNothing() : void
{
  // nothing here ...
}

Note: this type is useful with functions. It is possible to create variable with void type (let value : void = null) but it allows later to assign only null or undefined.

5. any type example

let a : any = 'text';

a = 123;
a = true;

console.log(`a=${a}`);

Output:

a=true

Note: with this type we can assign anything to variable. It shouldn't be used if it is not necessary.

 

Donate to Dirask
Our content is created by volunteers - like Wikipedia. If you think, the things we do are good, donate us. Thanks!
Join to our subscribers to be up to date with content, news and offers.

TypeScript

Native Advertising
🚀
Get your tech brand or product in front of software developers.
For more information Contact us
Dirask - we help you to
solve coding problems.
Ask question.

❤️💻 🙂

Join