Tell us what’s happening:
Why does the output say “undefined” when running it on codepen or devtools and also in VSCode when you run node in the terminal?
Your code so far
let catName;
let quote;
function catTalk() {
"use strict";
catName = "Oliver";
quote = catName + " says Meow!";
}
console.log(catTalk());
var catName;
var quote;
function catTalk() {
"use strict";
catName = "Oliver";
quote = catName + " says Meow!";
}
catTalk();
Your browser information:
User Agent is: Mozilla/5.0 (Macintosh; Intel Mac OS X 10_15_5) AppleWebKit/605.1.15 (KHTML, like Gecko) Version/13.1.1 Safari/605.1.15.
Challenge: Explore Differences Between the var and let Keywords
I’ve edited your post for readability. When you enter a code block into a forum post, please precede it with a separate line of three backticks and follow it with a separate line of three backticks to make it easier to read.
You can also use the “preformatted text” tool in the editor (</>) to add backticks around text.
Not sure I understand. It works when I enter it in freecodecamp browser and doesn’t give me “undefined” yet, when I use it in VS Code or codepen, it gives me “undefined”.
Right, I don’t know how it would have without the return. There is a way to do it without a return if you use an arrow function (you’ll learn that later) but with a function like you’re writing it, if you’re not using an explicit return, it’s not returning anything, in other words it’s returning undefined.
Yeah, that’s why I was surprised that it did work in the browser without the return statement. This is why I always work in my editor and get it working there first so I get used working like I normally would build. Mystery