Show Output
<!DOCTYPE html> <html lang="en"> <head> <meta charset="utf-8"> <title>JavaScript Convert Values to Numbers</title> </head> <body> <script> document.write(Number("10.5") + "<br>"); // Prints: 10.5 document.write(Number(true) + "<br>"); // Prints: 1 document.write(Number(false) + "<br>"); // Prints: 0 document.write(Number(null) + "<br>"); // Prints: 0 document.write(Number(" 123 ") + "<br>"); // Prints: 123 document.write(Number(" ") + "<br>"); // Prints: 0 document.write(Number("") + "<br>"); // Prints: 0 document.write(Number("123e-1") + "<br>"); // Prints: 12.3 document.write(Number("0xFF") + "<br>"); // Prints: 255 (hexadecimal representation) document.write(Number("undefined") + "<br>"); // Prints: NaN document.write(Number("null") + "<br>"); // Prints: NaN document.write(Number("Hello World!")); // Prints: NaN </script> </body> </html>