0
0
Javascriptprogramming~5 mins

Assignment operators in Javascript - Cheat Sheet & Quick Revision

Choose your learning style9 modes available
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?
AAdds the right value to the left variable and assigns the result to the left variable
BAssigns the right value to the left variable without change
CSubtracts the right value from the left variable
DMultiplies the left variable by the right value
Which operator assigns a value only if the left variable is falsy?
A+=
B||=
C&&=
D*=
What does x &= y do?
APerforms bitwise OR between x and y, then assigns to x
BAdds x and y, then assigns to x
CAssigns y to x if x is falsy
DPerforms bitwise AND between x and y, then assigns to x
Which operator multiplies and assigns in one step?
A*=
B/=
C+=
D-=
What is the result of let x = 5; x ||= 10;?
Ax is 10
Bx is 15
Cx is 5
DError
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.