FAQ: Variables - Create a Variable: let


#1

This community-built FAQ covers the “Create a Variable: let” exercise from the lesson "Variables ".

Paths and Courses
This exercise can be found in the following Codecademy content:

Web Development

Introduction To JavaScript

FAQs on the exercise Create a Variable: let

There are currently no frequently asked questions associated with this exercise – that’s where you come in! You can contribute to this section by offering your own questions, answers, or clarifications on this exercise. Ask or answer a question by clicking reply (reply) below.

If you’ve had an “aha” moment about the concepts, formatting, syntax, or anything else with this exercise, consider sharing those insights! Teaching others and answering their questions is one of the best ways to learn and stay sharp.

Join the Discussion. Help a fellow learner on their journey.

Ask or answer a question about this exercise by clicking reply (reply) below!

Agree with a comment or answer? Like (like) to up-vote the contribution!

Need broader help or resources? Head here.

Looking for motivation to keep learning? Join our wider discussions.

Learn more about how to use this guide.

Found a bug? Report it!

Have a question about your account or billing? Reach out to our customer support team!

None of the above? Find out where to ask other questions here!


#2

I have a question about using let as a variable. In one example, the value assigned to the variable after the = sign is put in quotes, and in other examples (the Boolean false and the number), no quotes were used. Is there an easy way to remember when quotes should be used and when they shouldn’t?


#3

The quotes is used only with string argument, boolean and number don’t need it.
If you put quotes around a number, or boolean, it will be treated as a String


#4

I ran both examples using var instead of let keyword in my browser console and both outputs where exactly the same as if using let (Burrito and 350). Based on this result, please help me better understand the differences.


#5

I would like to know the difference as well.


#6

So do ı … What’s difference?


#7

here is a good explanation:

https://stackoverflow.com/questions/762011/whats-the-difference-between-using-let-and-var-to-declare-a-variable-in-jav

which goes into more depth, the simplified version is that let is block scoped:

if (true){
   let letVariable = 'hello world';
   var varVariable = 'hello world';
   console.log(varVariable);
   console.log(letVariable);
}
console.log(varVariable);
console.log(letVariable); // syntax error or undefined

this is because the variable declared with let only exist within the if block (between the {})