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

In this lesson, you saw how one stray = in the thank-you check made the release note credit Maya on Theo’s day, and what an assignment produces in JavaScript.

  • In JavaScript, an assignment is an expression: it produces the value it assigns.
  • So a line like deployer = nextDeployer = "Maya" works in JavaScript as it does in Python. JavaScript groups it from the right: nextDeployer = "Maya" runs first and produces "Maya", and deployer takes that value.
  • In Python, the plain = is a statement, and only the walrus := produces a value. JavaScript needs no walrus.
  • A single = in a JavaScript condition assigns, and the if tests the value it produced. Where Python stops with a SyntaxError, JavaScript runs.
  • In a condition, compare with ===. Python’s parser stops the slip for you; in JavaScript, a linter, a checker much like Ruff, is what flags it, before the file runs.

The script starts both deployers at Maya, the agency’s lead. Here’s the port’s line, after the two names are declared:

Language: JavaScript
let deployer;
let nextDeployer;
deployer = nextDeployer = "Maya";
console.log("Next:", deployer, "then", nextDeployer);

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:02 In this lesson, you’ll see how one stray equals sign can make the release note credit the wrong person. First, a line you know: Python starts both deployers at Maya, the agency’s lead, in one line.

00:17 The JavaScript port declares both lets, then runs the same line, and both notes say: Next: Maya, then Maya.

00:27 JavaScript groups that line from the right. nextDeployer gets Maya first, and that assignment produces Maya. Then deployer takes that value.

00:39 So in JavaScript, an assignment is an expression: it produces the value it assigns. In Python, the plain equals sign is a statement, and only the walrus produces a value.

00:52 JavaScript needs no walrus.

00:56 The note also thanks Maya, the lead, on days she ships. Today Theo ships: Python checks with two equals signs, the port with three, and both say Deployed by: Theo.

01:10 Then a quick edit leaves the port’s condition with one equals sign. In Python, that slip stops the file before anything runs. Python asks if you meant two equals signs, or the walrus.

01:26 On Theo’s day, what does the JavaScript note print? Your turn: pause the video and predict.

01:38 It thanks Maya, and says Maya deployed.

01:44 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:55 And deployer keeps Maya, so the note credits the wrong person. Python makes you ask for this with a separate operator: with the walrus in its condition, Python prints the same two lines.

02:09 In JavaScript, the plain equals sign is that operator.

02:15 Only a const would have stopped it, with a TypeError. But deployer is a let, which can change.

02:24 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:38 Run it again: Deployed by: Theo.

02:42 Next up is Pick Today’s Status Line, an exercise: you port the status line without Python’s conditional expression.

Become a Member to join the conversation.