Use export to Reuse a Code Block

Tell us what’s happening:

Please help, Im not understanding why this is not a valid export.

Your code so far


"use strict";
const foo = "bar";
const boo = "far";
export { foo }

Your browser information:

User Agent is: Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/66.0.3359.181 Safari/537.36.

Link to the challenge:
https://learn.freecodecamp.org/javascript-algorithms-and-data-structures/es6/use-export-to-reuse-a-code-block

It is valid, but that isn’t what it’s asking you to do:

Below are two variables that I want to make available for other files to use. Utilizing the first way I demonstrated export, export the two variables.

I guess I’m hitting a brick wall then.
I’m not understanding what to do.

Take another look at the hint in the instruction.

export { capitalizeString } //How to export functions.
export const foo = "bar"; //How to export variables.

I’ve tried

export const foo = “bar”;

and it doesnt work

That’s the right code. So try closing your browser and if that doesn’t work, the delete cookies. Sometimes the database gets corrupted.

“use strict”;
const foo = “bar”;
const boo = “far”;

export const foo = “bar”;

Cleared cache and cookies, still isnt working.

I think I see the issue now. You are declaring the variable and then exporting. Just do it on one line.

So not

const foo = "bar"
export const foo = "bar"

Just

export const foo = "bar"

If you open up devtools, you’ll see the error in the console.

On chrome, right click over the instructions panel, select inspect, then choose the console tab.

2 Likes

Thank you so much. It was racking my brain.
Second time I tried just running
export const foo = “bar”
Nothing would happen.
I had deleted “use strict”;

1 Like

Your welcome. Remember to use the console as your first step in troubleshooting. It has saved me countless hours once I discovered it. You can also write console.log statements to it to see what you’re code is doing.

1 Like

Deleting “use strict” is not the answer.

I finally figured it out.

Final hint: don’t add any new lines of code. Only modify existing lines.

Solution:

"use strict";
export const foo = "bar";
export const boo = "far";

I hope FCC collects data on lessons submission attempts so they can see a spike and fix lessons like this one that have unclear instructions and/or overly strict rules.

8 Likes

Good job on solving this. It would be easier and better for you to just submit an issue about the unclear instructions. Do you know how to do that?

1 Like

Do you mean Issues · freeCodeCamp/freeCodeCamp · GitHub?

1 Like

Yes, exactly! It’s how FCC has developed and grown.

Just as a note, const can’t be redeclared. You can’t have const foo = then a few lines later const foo =, which is what you were doing. That’s why you need to just export const foo =, otherwise JS will correctly notice you’ve made and error, and will refuse to work.

1 Like

Thanks, you’re a life saver. Been on this for a while now wondering why it’s not working.

Exactly getting “Duplicate declaration error in the console”

Solution:

“use strict”;
export const foo = “bar”;
export const bar = “foo”;

I did the same thing,but couldn’t pass out.

“use strict”;
export const foo = “bar”;
export const bar= “foo”;
this was my code snippet…
Can’t find the reason,can you help please;

I was running into the same issue. What seemed to fix it for me was I added a space between “bar” and “=”.

From this:
“use strict”;
export const foo = “bar”;
export const bar= “foo”;

To This:
“use strict”;
export const foo = “bar”;
export const bar = “foo”;

13 Likes