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

ricky ebanks
ricky ebanks
1,212 Points

Question about writing let variable?

How is this code still running? i dont ever remember learning variables this way?? Thanks

const isAdmin = false; const isStudent = true;

let message; // Right here, how is this variable still running when writing a variable like this?? //

if ( isAdmin ) { message = 'Welcome admin'; }

1 Answer

Steven Parker
Steven Parker
231,261 Points

The keywords "let", "const", and "var" all declare new variables, and have a similar syntax. They have subtle differences in scope and hoisting behavior (which you won't notice in the examples at this level), and anything declared with "const" cannot be reassigned later.

ricky ebanks
ricky ebanks
1,212 Points

Ok thank you for your reply, I knew about the const and let, let being used when answer or reply is expected to change and const is used when it's not changed. I just never seen ( let message, ) used in this way and still get a prompt response.