Determining Return Values (Using the Console)

GaramYoonGaramYoon
1 min read
const number = Number(prompt('How many people?'));
if(number){
}

When the user clicks "Cancel" in prompt(), it returns null.

Since Number(null) results in 0, number is set to 0. This behaviour can be observed directly in the console. Before understanding truthy and falsy values, use the console actively to check what values are returned in different scenarios.

0
Subscribe to my newsletter

Read articles from GaramYoon directly inside your inbox. Subscribe to the newsletter, and don't miss out.

Written by

GaramYoon
GaramYoon