0

I can not understand the difference between statement and expression. I think there is always something missing because I can't understand well the meaning of expression evaluates to a value. For example, we say about variable declaration a statement (let x = 2;) because it does not give us a returned value so why we say about function like this (let foo = function () {};) an expression not a statement while it also does not give us a returned value ?

  • 1
    `let foo = function () {};` isn’t an expression. `(function () {})` is an expression. `let foo = function () {};` and `function foo() {}` are declarations. – Sebastian Simon Oct 04 '20 at 23:53
  • so what is (let foo) only or (let x) only is it a statement or expression? also, you mean that declarations are neither statement nor expression? – Muhammad Hossam Oct 07 '20 at 21:11
  • All expressions are also statements. JS code consists of a list of declarations and statements. However, that list is called a “statement list”. It’s all explained in the [specification](https://tc39.es/ecma262/#sec-ecmascript-language-statements-and-declarations). `let foo;` is a declaration, so is `function foo(){}`. `if(foo === 123){}` is a statement: an `if` statement. `foo = 123;` is a statement: an expression statement (where `foo = 123` is the expression — more precisely an assignment expression). – Sebastian Simon Oct 08 '20 at 01:07

0 Answers0