React Holiday

It’s Just an Expression

In our first email, I asked what you thought the most privileged type in React was. I said “array” — because I’m a big dork. Most everyone else said “function!”

I think we’re all right.

React itself has a special relationship with arrays. But — because it’s a JavaScript framework — it share’s JavaScript’s affinity for functions.

What’s an expression?

I’ve used the term “function expression” in previous emails to describe function syntax. But what is an expression?

In human terms, an expression is a way to ask and answer a question:

Question: greet(woodyVoice, "chantastic")?
Answer: "Howdy, howdy howdy, chantastic!"

And it doesn’t have to be complex. An expression is anything that gets evaluated: console.log("Hello" + " " + "world!")

Expressions are how arrays become lists, arrow functions become event handlers, and function declarations become React elements.

Seeing how these expressions can be exploited used in React is quite fun.

Take it home

Modern JavaScript and JSX can make expressions hard to spot. Open this CodeSandbox and count all the expressions you see.

Join us in Discord with your answer. I think this will spark a lively discussion.