Search This Blog

Javascript: number to string

  • Javascript/Typescript:
    const n = 1;
    const s1 = '' + 1;
    console.log(typeof s1); // string
    console.log(s1); // '1'
    
    const s2 = String(n);
    console.log(typeof s2); // string
    console.log(s2); // '1'
  • Typescript:
    const n = 1;
    const s1 = <string><any>n;
    console.log(typeof s1); // string
    console.log(s1); // '1'
    
    const s2 = n as any as string;
    console.log(typeof s2); // string
    console.log(s2); // '1'



see also

No comments:

Post a Comment