CS FundamentalsVery hardProduct-company placement · Node.js interview

In npm's semantic-version ranges, which versions does ^1.4.2 allow, and which does ^0.4.2 allow?

  1. A. ^1.4.2: >=1.4.2 <2.0.0; ^0.4.2: >=0.4.2 <0.5.0
  2. B. ^1.4.2: >=1.4.2 <1.5.0; ^0.4.2: >=0.4.2 <1.0.0
  3. C. Both allow any later version
  4. D. ^1.4.2: exactly 1.4.2; ^0.4.2: exactly 0.4.2

Correct answer: A. ^1.4.2: >=1.4.2 <2.0.0; ^0.4.2: >=0.4.2 <0.5.0

The caret allows changes that do not modify the left-most non-zero digit. For 1.x that permits minor and patch updates; for 0.4.x, where minor bumps may break, it permits only patches. ~1.4.2 would allow <1.5.0.

More Software Engineering, Git and Cloud Basics questions

Exams that ask this topic