JavaScript Expressions and Statements

Photo by Caspar Camille Rubin on Unsplash

Expressions

In simple terms an expression is a fragment of code that produce a value. It’s doesn't matter how big or small is it. Also we have two different types of expressions, expressions with side effects and those that in some sense evaluate and therefore resolve to a value. for example:

let x = 7 // produce variable x -> with side effects
3+4 //produce 7 as a result -> resolve to a value
5 //produce 5 -> resolve to a value

Also JavaScript has the following expression categories:

  1. Arithmetic: evaluates to a number, much of the time use arithmetic operators like addition, subtraction, division and multiplication.
  2. String: evaluates to a character string, for example, “Fred” or “234”. Generally uses string operator like addition.
  3. Logical: evaluates to true or false. uses logical operators (&& and ||).
  4. Primary expressions: Basic keywords and general expressions in JavaScript. for example this keyword and Grouping operator ().
  5. Left-hand-side expressions: Left values are the destination of an assignment. for example new operator to create an instance of a class and super keyword to call functions on an object’s parent.

Statements

A program is a list of statements and every statement is separated by a semicolon. The simplest statement look like this:

1;

Well, It isn’t too much, but when you combine statements with expressions you can create a program of any type of size.

If you want to know more about it, check out this, Eloquent JavaScript and MDN Web Docs for Statements and Expressions.

Passionate reading || Coding Addicted || FullStack Web Developer from Costa Rica

Get the Medium app

A button that says 'Download on the App Store', and if clicked it will lead you to the iOS App store
A button that says 'Get it on, Google Play', and if clicked it will lead you to the Google Play store