Choose Between Outcomes With else and ||

In Decide What Happens With if, you saw that code after an if block runs either way. Your next rules need two more things. They run one block or another, and they accept a record when either of two checks holds.

Otherwise: else

An else block right after an if block runs only when the condition is false:

Language: JavaScript
> const record = { id: "M-302", label: "praise" };
undefined
> if (record.label === "bug") {
…   console.log("Send to the developers");
… } else {
…   console.log("No action needed");
… }
No action needed

Exactly one of the two blocks runs.

Locked learning resources

Join us and get access to thousands of tutorials and a community of expert JavaScript developers.

Unlock This Lesson

Already a member? Sign-In

Locked learning resources

The full lesson is for members only. Join us and get access to thousands of tutorials and a community of expert JavaScript developers.

Unlock This Lesson

Already a member? Sign-In

Become a Member to join the conversation.