FAQ: Conditional Statements - Truthy and Falsy Assignment

No, it is assigning the evaluation of the expression on the right side. tool && 'pen' is an expression.

I think I understand.

If it was expressed this way, does it now mean I’m assigning two values?

let writingUtensil = tool + 'pen';

The value on the right is also an expression which is evaluated before assignment. It will be evaluated as concatenation of two strings and yield, 'markerpen'.

The basic definition of an expression is, anything that yields a value. That is to say that all expressions can be boiled down to a single value.

Given that we can express data in many dynamic forms and treating all values as expressions we can now settle on A and B, &c. as operands, then test our outer logic before expanding. In functional code we would abstract away expressions, but that is a topic for down the road.

A && B

A || B
1 Like

My brain’s fried. Does not compute. jk

I get it. Thanks for talking me through this @mtf!

1 Like

Hopefully QQ on the exercise page 6/11.
I’m trying to pay particular attention to when there are spaces between items and when there are not.
In the first example there is a space between the closed parenthesis following myVariable and the curly bracket.
In the second example with numbers there is no space between the closed parenthesis following numberOfApples and the curly bracket.
Am I comparing apples and oranges? Paying too much attention to spaces that would have no impact on running the script or is this a mistake in the example with numbers?
Thank you for teaching me JavaScript!

Please give us an example.

let tool = ‘marker’;

// Use short circuit evaluation to assign writingUtensil variable below:

let writingUtensil = tool || ‘pen’

console.log(The ${writingUtensil} is mightier than the sword.);

My question if tool and pen are both nether falsey why does it return marker instead of pen?

short circuit, if both are true, only the first option is evaluated and used