Welcome to the Treehouse Community

The Treehouse Community is a meeting place for developers, designers, and programmers of all backgrounds and skill levels to get support. Collaborate here on code errors or bugs that you need feedback on, or asking for an extra set of eyes on your latest project. Join thousands of Treehouse students and alumni in the community today. (Note: Only Treehouse students can comment or ask questions, but non-students are welcome to browse our conversations.)

Looking to learn something new?

Treehouse offers a seven day free trial for new students. Get access to thousands of hours of content and a supportive community. Start your free trial today.

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 "".