Bird
0
0

Given the code below, what will be the output?

medium📝 component behavior Q13 of 15
Node.js - Worker Threads
Given the code below, what will be the output?
const sab = new SharedArrayBuffer(4);
const int32 = new Int32Array(sab);
int32[0] = 10;
Atomics.add(int32, 0, 5);
console.log(int32[0]);
A10
B5
C15
DNaN
Step-by-Step Solution
Solution:
  1. Step 1: Understand initial value and Atomics.add

    The int32[0] is set to 10. Then Atomics.add adds 5 to this value atomically.
  2. Step 2: Calculate the new value

    10 + 5 = 15, so int32[0] becomes 15.
  3. Final Answer:

    15 -> Option C
  4. Quick Check:

    Atomics.add adds value safely = 15 [OK]
Quick Trick: Atomics.add adds value and returns old value, array updates [OK]
Common Mistakes:
  • Expecting Atomics.add to return new value
  • Ignoring atomic operation effect
  • Confusing initial and updated values

Want More Practice?

15+ quiz questions · All difficulty levels · Free

Free Signup - Practice All Questions
More Node.js Quizzes