FAQ: Code Challenges: JavaScript Fundamentals - Introduction

This community-built FAQ covers the “Introduction” exercise from the lesson “Code Challenges: JavaScript Fundamentals”.

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

Web Development

FAQs on the exercise Introduction

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!

Got this error when running my code for this challenge.

Your function should return the string 'Hello, World!' . Expected: Hello, World! but your function returned: 'Hello, World!' . Our test invoked your function and saved the value it returned. We expected it to equal the exact value specified ( 'Hello, World!' ) and found it did not.

Here’s my code:

const greetWorld = ()=>{
  const greet = "'Hello, World!'";
  return greet;
};

Is the problem with CD or my code?

1 Like

Hey letronique,

Not sure if you’re still stuck on this one, but I hit the same error just now.

After looking at the solution they provided apparently the real solution requested is Hello, World! and not ‘Hello, World!’, as in the code accepted my answer as correct once I removed the apostrophes around the string.

1 Like

you don’t need the variable, just:
return “Hello, World!”;

1 Like

In the “Helpful Notes:” section of this exercise, it explains that our code for this exercise can be either a function expression or a function declaration. What is the difference?

I looked up on Mozilla Development Network’s MDN documentation, but the answer is still unclear and also introduced another term–function statement. So my question is, what is i the different between function declaration, function expression, and function statement?

1 Like

I think I got it. But I know I’m going to get this mixed up in the future, lol.

a function expression is starts with
const function_name = () => {};

whereas a declaration
const function_name = function () {};

Looks like you might have an extra set of quotes surrounding Hello, World!

Actually, both are anonymous function expressions.

Consider the example:

// Function Declaration
function func1() {
    console.log("Hello");
}

// Anonymous Function Expression (arrow syntax)
const func2 = () => {
    console.log("Hello");
};

// Anonymous Function Expression
const func3 = function() {
  console.log("Hello");  
}

// Named Function Expression
const func4 = function greet() {
    console.log("Hello");
}

Only func1 is a function declaration. The rest are function expressions.

// Declarations and expressions
...

// Function Calls (All of them work)
func1();  // Output: Hello
func2(); // Output: Hello
func3(); // Output: Hello
func4(); // Output: Hello

Contrast this with the function calls being placed before the declarations and expressions.

// Function Calls (Only the Function Declaration version works)
func1();  // Output: Hello 
func2(); // Error - function not defined
func3(); // Error - function not defined
func4(); // Error - function not defined

// Declarations and expressions
...

That has to with hoisting. Function declarations are hoisted, so they can be called even if the calls are placed before the declaration. Function expressions aren’t hoisted.

Some other links:

here is my version using arrow function expressions

const greetWorld = () => “Hello, World!”;

console.log(greetWorld());