Basic JavaScript: Compound Assignment With Augmented Addition

Hello all. Beginner coder here.

I’m running through the lesson in the Title, understand the concept, but in the example:

var myVar = 1;
myVar += 5;
console.log(myVar); // Returns 6

I have no idea what the last line (apart from // Returns 6 - although i can’t remember what // x or /* x*/ is called i know it isn’t part of the code it’s just an instructional line) means. It’s not mentioned in the lesson. Any help appreciated!

Thanks,
Matt

These “instructional lines” are called comments. // creates a one line comment and with /* ... */ you can create multi line comments:

/* multi
   line
   comment */

console.log() outputs the return value of the expression between it’s brackets to the console of your browser’s developer tools. (or in the case of the FCC practice environment, to it’s console)

1 Like

hmm, thanks. I’m still a little lost on the console bit - would you mind breaking it down a little more for me? (thank you for your patience - it’s literally day one for me!)

the return value of the expression - in this case ‘myVar’?

the console of FCC’s practice environment - a quick Google seems to suggest that this is the combination of a monitor and keyboard… i’m assuming this isn’t what you’re referring too? What is the actual purpose of this command in practical terms?

Thanks again Michael, really appreciate your help.

Matt

when you have a variable, its return value is just the value inside the variable
going forward you will meet functions, and it will introduce the concept of returned values for that.

the practice environment is the FCC editor, and the console is the bit of the screen below it where you see the test results, you can also see there the values printed from console.log() statements

the console, and the console.log() statements are powerful debugging tools, they let you see the values of whatever you put inside the parenthesis of the console.log statement

so, in the case of this code

the first line initialize myVar to 1, second line increase its value by 5, and the third line will print the value of myVar to the console

3 Likes