JavaScript JavaScript Arrays Loop Through Arrays Search for a Value in an Array

Hanwen Zhang
Hanwen Zhang
18,515 Points

what does the "let message" works here, why there is nothing followed after this "let message" ?


1 Answer

Hi Hanwen!

let message;

...declares the variable "message" (literally - the memory space, which is referenced by message), without assigning it a value, which is done later in the code.

In the if else block, message is then set (assigned a value) depending on the conditions.

It's just a non-redundant way to declare a variable first when you need to later reference it in several different places.

Does that make sense?

I hope that helps.

Stay safe and happy coding!