Question on Javascript Scope Exercise: Apartment


#1


https://www.codecademy.com/courses/learn-javascript/lessons/scope/exercises/functional-scope?action=lesson_resume&link_content_target=interstitial_lesson


Hi, sorry if this seems like a super basic question but I was wondering if anyone could explain this code to me. I posted the 'hint' offered by Codecademy in the exercise.

What I don't understand is, why is mailBoxNumber a variable but laundryRoom isn't? Also, what is the console.log(' ... ') for?

Thanks in advance!


function myApartment() {
  var mailBoxNumber = 'Box 3';
  laundryRoom = 'In-unit';
  console.log(' ... ');
}

myApartment();


#2

So there is one big difference between these two lines of code. The key word var declares variables. So when it is put before mailBoxNumber that declares it as a variable.

Regarding console.log check out this thread. https://www.codecademy.com/en/forum_questions/5479b60480ff33483b0029cc


#3

Thank you for the explanation!


#4

Both of them are variables but this is the first time we're using 'mailBoxNumber' so we have to declare it with 'var'. The reference to laundryRoom is using the same laundryRoom variable that we declared above.

In step 4 you're asked to log the 'mailBoxNumber' outside the function. What does it print out and why?


#5

This topic was automatically closed 7 days after the last reply. New replies are no longer allowed.