Locked learning resources

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

Unlock This Lesson

Locked learning resources

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

Unlock This Lesson

Assigning by Mistake in a Condition

Assigning by Mistake in a Condition

JavaScript’s ordinary = changes a name and produces the assigned value. Python requires := for an assignment expression; its plain assignment is a statement.

After declaring both JavaScript names, a chain works like Python’s deployer = next_deployer = "Maya":

Language: JavaScript
let deployer;
let nextDeployer;
deployer = nextDeployer = "Maya";

JavaScript groups this from the right. nextDeployer = "Maya" produces "Maya", which is then assigned to deployer.

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

00:00 In this lesson, you’ll catch a stray equals sign in the release note’s thank-you check. Maya is the lead, but today Theo ships. Python checks with two equals signs, JavaScript with three.

00:13 Both say Deployed by: Theo. Then a quick edit leaves the port’s condition with one equals sign.

00:24 In Python, that slip stops the file before anything runs. Python asks if you meant two equals signs, or the walrus. On Theo’s day, what does the JavaScript note print?

00:37 Your turn: pause the video and predict.

00:46 It thanks Maya, and says Maya deployed.

00:51 The single equals sign assigns Maya to deployer and produces Maya. A non-empty string counts as true, as in Python, so the if runs its block.

01:03 And deployer keeps Maya, so the note credits the wrong person. After declaring both names with let, a chained assignment works like Python’s.

01:14 JavaScript groups it from the right. nextDeployer gets Maya first, and that assignment produces Maya. Then deployer takes that value.

01:26 An assignment is an expression in JavaScript: it produces the value it assigns. Python requires the walrus for an assignment expression; JavaScript’s ordinary equals sign already produces a value.

01:41 A const would stop the mistaken assignment with a TypeError. But deployer is a let because the script swaps today’s and tomorrow’s deployers.

01:53 Python’s parser stops this slip for you. In JavaScript, a linter, a checker much like Ruff, is what flags it, before the file runs. And in a condition, compare with three equals signs.

02:07 Run it again: Deployed by: Theo. Next up is Pick Today’s Status Line, an exercise: you port the release note’s status line.

Become a Member to join the conversation.