Blocks and Scope question!


#1

https://www.codecademy.com/courses/learn-javascript-scope/lessons/scope/exercises/block-scope-iii?action=resume_content_item&course_redirect=introduction-to-javascript.

Hey guys! I need your help once again!
Maybe I misunderstood how declaration, expression and arrowing works. But I have tried to implement declaration and for some reason it didn’t work out.

So, here is the example of the same task by using arrowing

const city = 'New York City';

const logCitySkyline = () => {
  let skyscraper = 'The Empire State Building';
  return 'The stars over the ' + skyscraper + ' in ' + city;
  console.log(logCitySkyline());
}

However, when I try to make it as a Declaration

const city = 'New York City';

function logCitySkyline() {
let skyscraper = 'The Empire State Building';
 return 'The stars over the ' + skyscraper + ' in ' + city;
  console.log(logCitySkyline());

It just gives me an error. I would appreciate if anyone can explain how this code supposed to look like by using (declaration and expression) . For some reason struggling with functions topic…


#2

in the first code, why is the function call:

console.log(logCitySkyline());

nested in the function?

for the second code, it looks fine except you forgot a } to close of the function


#3

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