In JavaScript we have expression and statement. Even though I read the definition about it multiple times, after a while, I still forget which one is which. So, this post is a reminder for everyone like me who confuses these two, so you will never forget it but always keep in mind the difference between expression and statement.

Image for post

Photo by bruce mars on Unsplash

A JS expression is any valid code that resolves into a value and can be written whenever you would expect a value. Usually expression are written in only one line. For example:

  • 42 // a number
  • “Hello World” // a string
  • 42 + 1 // a calculation
  • x = 42 + 1 // calculation
  • myVar // a variable
  • myFun() // a function that returns a value

But it’s more complicated than you think . There are different types of expressions:

  • Arithmetic: Resolves to a number, e.g.

42

42 + 1

etc.

  • String: Resolves to a string, e.g.

"Hello World"

"123"

etc.

#difference-between #difference #statement #expression #javascript #programming

What is an expression and what is a statement in JavaScript 
1.25 GEEK