Loading

Quipoin Menu

Learn • Practice • Grow

node-js / Semantic Versioning
interview

Q1. What is semantic versioning (SemVer)?
Semantic versioning is a versioning scheme with format MAJOR.MINOR.PATCH. MAJOR changes for incompatible API changes, MINOR for adding functionality in a backward-compatible manner, and PATCH for backward-compatible bug fixes. npm uses SemVer to manage package versions and dependencies.

Q2. What do the symbols ^ and ~ mean in package.json?
^ (caret) allows updates that do not change the leftmost non-zero digit: ^1.2.3 allows 1.x.x but not 2.0.0. ~ (tilde) allows patch updates: ~1.2.3 allows 1.2.x but not 1.3.0. Exact version (1.2.3) installs exactly that version. These symbols help manage updates while respecting compatibility.

Q3. What's the difference between ^1.0.0, ~1.0.0, and 1.0.0?
^1.0.0 means any version >=1.0.0 and <2.0.0 (compatible with major version 1). ~1.0.0 means >=1.0.0 and <1.1.0 (only patch updates). 1.0.0 is exact - only that version. Choose based on how much change you're willing to accept in your dependencies.

Q4. How do you update packages according to SemVer?
npm update updates packages to the latest version that satisfies the version range in package.json. npm outdated shows which packages are outdated. For major updates beyond the range, you need to manually change package.json or use npm install @latest.

Q5. Why is semantic versioning important?
SemVer helps developers understand the impact of updating dependencies. You can safely update patch and minor versions expecting no breaking changes. It also helps package authors communicate changes clearly. npm's dependency resolution relies on SemVer to find compatible versions.