Wednesday, July 8, 2026
HomeLanguagesJavascriptTypeScript | toString() Function

TypeScript | toString() Function

The toString() method in TypeScript is used to returns a string representing the specified object radix (base).

Syntax:

number.toString( [radix] )

Parameter: This function accept asingle parameter as mentioned above and described below:

  • radix: This parameter represents an integer between 2 and 36 specifying the base to use for representing numeric values.
  • Return Value: Returns a string representing the specified Number object.

    Below examples illustrates the toString() function in TypeScript

    Example 1:

    javascript




    // The toString()function
    let Num1: number = 123;
    Num1.toString(); 
    Num1.toString(16); 
    Num1.toString(8); 
    Num1.toString(4);

    
    

    Output:

    123 
    7b
    173
    1323
    

    Example 2:

    javascript




    // The toString() function
    let Num2: number = 12345;   
    console.log("Number Method: toString()");  
    console.log(Num2.toString());  
    console.log(Num2.toString(4));

    
    

    Output:

    Number Method: toString()
    12345
    3000321
    
    Dominic
    Dominichttp://wardslaus.com
    infosec,malicious & dos attacks generator, boot rom exploit philanthropist , wild hacker , game developer,
    RELATED ARTICLES

    5 COMMENTS

    Most Popular

    Dominic
    32519 POSTS0 COMMENTS
    Milvus
    131 POSTS0 COMMENTS
    Nango Kala
    6900 POSTS0 COMMENTS
    Nicole Veronica
    12016 POSTS0 COMMENTS
    Nokonwaba Nkukhwana
    12111 POSTS0 COMMENTS
    Shaida Kate Naidoo
    7019 POSTS0 COMMENTS
    Ted Musemwa
    7263 POSTS0 COMMENTS
    Thapelo Manthata
    6978 POSTS0 COMMENTS
    Umr Jansen
    6968 POSTS0 COMMENTS