Semantic Versioning Quiz: Ten Questions, Answers Included

Cover the answer under each question with your hand or a sheet of paper, decide what you think, then read on. The answers follow the Semantic Versioning 2.0.0 specification at semver.org. Count one point per correct answer; there is a short note on scores at the end.

Questions 1 to 5: choosing the bump

1. Your library is at 2.4.1. You fix a bug without changing any public signatures. What is the next version?

Answer: 2.4.2. A backward-compatible bug fix increments the patch number only.

2. At 2.4.2 you add a new optional parameter to an existing function. Next version?

Answer: 2.5.0. New backward-compatible functionality is a minor change, and the patch number resets to zero.

3. You mark a function as deprecated but it still works. Which part should change?

Answer: minor. The specification says deprecating functionality in the public API should come with a minor version increment, so that users notice it before the removal in a later major.

4. You fix a bug, and the fix changes the return value that some users were relying on. Patch or major?

Answer: technically major if the old behaviour was part of the documented API. Semver is defined relative to the public API. If the documentation promised the old value, changing it breaks the contract even when it was a bug. If the behaviour was undocumented and clearly wrong, many maintainers ship it as a patch with a loud changelog note, but that is a judgement call the spec does not make for you.

5. You accidentally publish a breaking change in a minor release. What does the spec recommend?

Answer: publish a new minor that restores compatibility. The FAQ on semver.org advises correcting the problem and releasing a new minor version; do not modify the already published release.

Questions 6 to 10: ordering and special cases

6. Which is higher: 1.0.0-alpha or 1.0.0?

Answer: 1.0.0. A pre-release version has lower precedence than the associated normal version.

7. Put these in order: 1.0.0-beta.11, 1.0.0-beta.2, 1.0.0-beta.

Answer: 1.0.0-beta, then 1.0.0-beta.2, then 1.0.0-beta.11. Numeric identifiers compare as numbers, so 2 comes before 11, and a shorter set of identifiers ranks lower when all preceding ones are equal.

8. Are 1.0.0+build.1 and 1.0.0+build.2 different versions for precedence?

Answer: no. Build metadata after the plus sign is ignored when determining precedence.

9. What does a version of 0.7.3 promise about stability?

Answer: nothing. Major version zero is for initial development; anything may change at any time. Package managers add their own conventions on top (npm's caret treats 0.x minors as breaking), but the spec itself promises nothing.

10. Is "v1.2.3" a semantic version?

Answer: no, but it is a common tag name. The FAQ states that "v1.2.3" is not a semantic version, although prefixing tags with "v" is a widespread convention. The version inside your package metadata should be the bare number.

How did you do?

ScoreSuggestion
9 to 10You know the spec well. Try the harder cases on the semver edge cases page.
6 to 8Solid on bumps; reread the precedence rules in semantic versioning explained.
0 to 5Start with the guide above, then the npm semver ranges training unit, which shows how the rules affect installs.

More self-checks are listed in the self-checks index.

Related pages