Recall & Review
beginner
What does the
= operator do in JavaScript?The
= operator assigns the value on the right to the variable on the left. For example, x = 5 sets the variable x to 5.Click to reveal answer
beginner
What is the difference between
= and += operators?= assigns a value directly, while += adds the right value to the left variable and then assigns the result back. For example, x += 3 means x = x + 3.Click to reveal answer
beginner
List three compound assignment operators in JavaScript besides
+=.Three common compound assignment operators are:<br>1.
-= (subtract and assign)<br>2. *= (multiply and assign)<br>3. /= (divide and assign)Click to reveal answer
intermediate
What happens if you use
x ||= y in JavaScript?The
||= operator assigns y to x only if x is falsy (like null, undefined, 0, or ''). It's a shortcut for x || (x = y).Click to reveal answer
intermediate
Explain the difference between
&= and ^= operators.&= performs a bitwise AND between the variable and the right value, then assigns the result back.<br>^= performs a bitwise XOR (exclusive OR) between the variable and the right value, then assigns the result back.Click to reveal answer
What does the operator
+= do in JavaScript?✗ Incorrect
+= adds the right value to the left variable and stores the result back in the left variable.Which operator assigns a value only if the left variable is falsy?
✗ Incorrect
||= assigns the right value only if the left variable is falsy.What does
x &= y do?✗ Incorrect
&= performs bitwise AND and assigns the result to the left variable.Which operator multiplies and assigns in one step?
✗ Incorrect
*= multiplies the left variable by the right value and assigns the result back.What is the result of
let x = 5; x ||= 10;?✗ Incorrect
Since 5 is truthy,
||= does not assign 10 to x, so x remains 5.Explain how compound assignment operators work in JavaScript with examples.
Think about how you can shorten 'x = x + 3' using a compound operator.
You got /3 concepts.
Describe the purpose and behavior of logical assignment operators like ||= and &&=.
Consider how these operators help assign values only under certain conditions.
You got /3 concepts.