TheOdinProject / curriculum

The open curriculum for learning web development

Home Page:https://www.theodinproject.com/

Geek Repo:Geek Repo

Github PK Tool:Github PK Tool

Variables and Operators: Wrong suggestion about declaration with an assignment about returning undefined value.

bibekchand opened this issue · comments

Checks

Describe your suggestion

In the javascript basics section, in variable and operator chapter at the last line: "however for now it is good to remember that a declaration with an assignment (such as let b = 7 * a) returns undefined and so you cannot declare and assign a value to a variable and read its value in the same line."

This is not true now. The javascript allows you to do that right now.

Path

Foundations

Lesson Url

https://www.theodinproject.com/lessons/foundations-variables-and-operators

(Optional) Discord Name

crap_momo.

(Optional) Additional Comments

No response

Thanks for creating this issue @bibekchand. There's a misunderstanding here with what that line means. The key part is "cannot declare and assign and read its value on the same line".

In your example, you declared and assigned a variable on one line, then on a separate line, read the value of it using console.log. That's perfectly fine to do.

If you go into the browser console and enter just a = 1, you'll see the next line shows <- 1 meaning it assigned the variable and read its value, returning its value all at the same time.
But if you did let a = 1 instead (i.e. declaring the variable with let), you'll see <- undefined because it can't read the value in one go at the same time as declaring and assigning.

image

You can do whatever you want in separate statements perfectly fine.

Closing as the current instructions are correct and no further action is required.