liveBook · Manning

Expression

As explained in Secrets of the JavaScript Ninja, Third Edition

An expression is a JavaScript construct that evaluates to a value and can occur within a larger expression or statement.

An expression is a JavaScript construct that evaluates to a value. Expressions can appear inside larger expressions or statements. A function declaration must stand alone as a statement; a function expression appears as part of another statement, such as an assignment or function call. section 5.1.1

Functions can be written as expressions, assigned to variables, passed as arguments, or returned from other functions. Arrow functions provide another expression form: a concise body can return an expression’s value without braces or an explicit return. section 5.1.1 section 5.1.2

Listing 5.3 Comparing an arrow function and a function expression
const greet = name => "Greetings " + name;     #A
console.assert(greet("Oishi") === "Greetings Oishi",
       "Oishi is properly greeted"); 

const anotherGreet = function(name){     #B
  return "Greetings " + name;            #B
};                                       #B
console.assert(anotherGreet("Oishi") === "Greetings Oishi",  
       "Again, Oishi is properly greeted"); 

Compare an arrow function with a function expression that both greet a name. section 5.1.2

How Secrets of the JavaScript Ninja, Third Edition covers it

How deep it goes
Explains function-expression placement and concise arrow-function bodies, without surveying expression types generally.
Examples
Uses greeting and hypotenuse functions to compare arrow syntax with function expressions.
What you can do after
Understand how function expressions fit into assignments, calls, and concise arrow-function definitions.
How it connects
Connects expressions to function declarations, function expressions, arrow functions, assignments, and function calls.

Also explained in

Compare how 14 books explain expression →

Related concepts

This explainer was generated by Manning's knowledge graph from the text of Secrets of the JavaScript Ninja, Third Edition. The section links point to the parts of the book it draws on.