Easy learning with example program codes

TypeScript number object tutorial

TypeScript number object:

The TypeScript Number object represents numerical data which can be integers or floating-point numbers.

TypeScript number constants/properties:

Property Description
MAX_VALUE It specify the largest possible value.
MIN_VALUE It specify the smallest possible value.
NaN Equal to a value that is not a number.
NEGATIVE_INFINITY A value that is less than MIN_VALUE.
POSITIVE_INFINITY A value that is greater than MAX_VALUE

TypeScript number methods:

Methods Description
toExponential(fractionDigits) It returns a string representing theĀ number object in exponential notation.
toFixed(digits) It limits the number of digits after decimal value.
toPrecision(digits) It formats the number with given number of digits.
toString() It converts number into string.
valueOf() It converts other type of value into number.

How to create TypeScript number object:

  • By using number literals.
  • By using Number() constructor.

By using number literals:

When we create a number literal browser automatically converts it to Number object.


var num1:number = value;


function numTest(num1:number):void{

Try it:

JS Bin on

By using Number() constructor:

We can create a TypeScript Number object by using Number() constructor. It returns NaN if value is not a number.


var num1 = new Number(value);


function numTest(num1:number):void{
var num1 = new Number(123);
var num2 = new Number("Hello");

Try it:

JS Bin on

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 © 2018 CodesJava Protection Status SiteMap