What is type conversions in javasript?



Most of the time, operators and functions automatically convert the values given to them to the right type.

let value = true;

alert(typeof value); // boolean

value = String(value); // now value is a string "true"

alert(typeof value); // string


<!DOCTYPE HTML>

<html>

<body>

    <p>Before the script...</p>

    <script>

        alert(Boolean(1)); // true

        alert(Boolean(0)); // false


        alert(Boolean("hello")); // true

        alert(Boolean("")); // false

    </script>

    <p>...After the script.</p>

</body>

</html>

0 Comment's

Comment Form