The Number()
method explicitly converts a boolean to a number. In this shot, we learn to convert a boolean value to a number.
Number(booleanValue)
booleanValue
: This is the boolean value we want to convert to a number.
A number is returned.
// create some boolean valueslet bool1:Boolean = falselet bool2:Boolean = true// convert to Numberslet num1 = Number(bool1)let num2 = Number(bool2)// print the numbersconsole.log(num1) // 0console.log(num2) // 1
Number()
method. Then, we save the results.