Statement vs expression vs assignment in JavaScript

Viewed 130

I understand that a variable declaration is a statement (and not an expression, as it cannot be evaluated)

let a

I understand that an assignment is also a statement and an expression, as it can be evaluated in JS)

a= 2

I also understand that when I declare and assign a value in the same line, this is considered a statement and not an expression, as it cannot be evaluated:

let a = 5

My question is:

If these 2 things (declaration + assignment) are happening in the same line, why is it considered a declaration?

An expression is expected as an argument here:

console.log(let a=3)
> Uncaught SyntaxError: missing ) after argument list

but an assignment is an expression as it can indeed be passed as an argument:

console.log(a=3)
3
0 Answers
Related