Welcome to the Treehouse Community

Want to collaborate on code errors? Have bugs you need feedback on? Looking for an extra set of eyes on your latest project? Get support with fellow developers, designers, and programmers of all backgrounds and skill levels here with the Treehouse Community! While you're at it, check out some resources Treehouse students have shared here.

Looking to learn something new?

Treehouse offers a seven day free trial for new students. Get access to thousands of hours of content and join thousands of Treehouse students and alumni in the community today.

Start your free trial

JavaScript Introduction to Programming Control Structures If/Else

Davide Pugliese
Davide Pugliese
4,091 Points

Which state does name transits to when no name is provided in the prompt?

Hello, I would like to know in this video when we have:

name = prompt ("What's your name?");

if (name) {
       ...
}

which state does name transit to if no name is provided in the prompt: null or undefined?

I guess it should go to undefined since it was not assigned any value to it. Is it correct?

2 Answers

Valdas Japertas
Valdas Japertas
4,522 Points

Neither. It gets a value of empty string (""). You can test this using Chrome's JavaScript console:

var username

username = prompt("What is your name?")

username

You will see that console will write "undefined" at first, but after the promt it will give the values of username as "".