Search
 
SCRIPT & CODE EXAMPLE
 
CODE EXAMPLE FOR JAVASCRIPT

how to cast in javascript

Converting Strings to Numbers
Converting Numbers to Strings


Number("3.14")    // returns 3.14
Number(" ")       // returns 0
Number("")        // returns 0
Number("99 88")   // returns NaN



let y = "5";      // y is a string
let x = + y;      // x is a number


let y = "John";   // y is a string
let x = + y;      // x is a number (NaN)


String(x)         // returns a string from a number variable x
String(123)       // returns a string from a number literal 123
String(100 + 23)  // returns a string from a number from an expression

 
PREVIOUS NEXT
Tagged: #cast #javascript
ADD COMMENT
Topic
Name
3+9 =