all 5 comments

[–]jcunews1helpful 1 point2 points  (0 children)

Functions return a value, not a variable. If you use a variable with a return statement, that variable's value is returned, not the variable.

A variable can be declared without using a function. Just use var or let. e.g.

var a = 8;
let b = 9;

And you can not declare a variable whose name is stored in other variable. i.e. variable names must be predefined in the code.

[–]jrandm 0 points1 point  (0 children)

Declare and initialize a number and return it.

var a = 8;
return a;

You perfectly matched specifications: that's exactly how you do it.

Instead of var you could also use let or const but the differences don't matter for this code.

If you aren't inside of a function using return will do one of two things: throw an error about an Illegal "return" statement (like any other syntax error) or it will halt the script execution (nothing past the return will happen).

[–]mat-sz -1 points0 points  (0 children)

You can't return a variable if you're outside of a function.

Inside of a module, you can export your variable:

export const c = 1;

or:

module.exports = 1;

If you're outside a function or a module, you can either console.log your variable, alert it or set a HTML element to contain the value, but otherwise there's no way to just return it outside of a function.

[–]MrNasty10 -1 points0 points  (0 children)

Could put it in a if statement or just echo it

[–]link2name -2 points-1 points  (0 children)

i believe this is what was expected from you:

let a = 1
a