Demystifying Semantic Versioning

Omkar Bhavare
3 min readNov 8, 2023

--

In this section, we’ll cover the basics of Semantic Versioning — what it is, the various types of versions, and an in-depth exploration of version upgrades. We’ll also discuss how these versioning practices can impact our code. Let’s dive right in! 💻✨

🤔 What is Semantic Versioning ?
Sematic Versioning is a way to specify and convey the changes made in the software / packages based on it’s version number.

🖋️ Version Number Structure

example: if version number of any dependency is 2.6.3
Here ,

Major version number is 2 
Minor version number is 6
Patch version number is 3
  1. MAJOR Version:
    Indicates significant updates that may break existing functionality or APIs.
    Increments for backward incompatible changes.
example: 
ejs : 2.2.9
ejs: 3.2.9

Backward Incompatibility : It refers that the new updated version is not fully compatible with the older version as there might be some structural changes in code or removal of the some feature

// Version 1.0.0
function calculateSum(a, b) {
return a + b;
}
function calculateProduct(a, b) {
return a * b;
}
// Version 2.0.0
function calculateSum(a, b) {
return a + b;
}
// calculateProduct function is removed in this version

2. MINOR Version:
Indicates the introduction of new functionality without breaking existing features.

Increments for backward-compatible additions of features.

example: 
ejs : 3.2.9
ejs: 3.4.9

Backward-Compatibility : It refers to ability of a newer version of software to work seamlessly with system or code that was designed for older version.

// Version 1.0.0
function calculateSum(a, b) {
return a + b;
}

In Version 1.1.0, a backward-compatible change is made by adding a new function, calculateAverage , without modifying or removing any existing functionality.

// Version 1.1.0
function calculateSum(a, b) {
return a + b;
}

// New backward-compatible feature added
function calculateAverage(a, b) {
return (a + b) / 2;
}

3.PATCH Version:
Indicates the correction of issues without introducing new features mostly done for Security and Bugs fixes

example: 
ejs : 3.3.1
ejs: 3.3.2

4. Beta Version:
A pre-release version for testing, signaling that it’s not yet a final, stable release.
[beta is often used to indicate a version that is still in testing or development.]

{
"dependencies": {
"library": "2.0.0-beta.1"
}
}

Beta versions invite users to test upcoming features and report issues before the stable release, allowing developers to gather feedback and ensure software readiness for widespread use.

5. Metadata:
Metadata provides additional information about the build or release but does not affect the previous version feature or compatibility.

{
"dependencies": {
"library": "1.2.3+build456"
}
}

😀 Let’s see what is Version Upgrade:

  1. Caret ( ^ ) : Allows only MINOR & PATCH version upgradation automatically.
example: 
{
"dependencies": {
"ejs": "^3.3.1"
}
}
ejs: 3.3.2 // allowed Patch Version fix
ejs: 3.4.2 // allowed Minor Version fix
ejs: 4.1.0 // not allowed Major Version fix

2. Tilde ( ~ ) : Allows only PATCH version upgradation automatically.

example: 
{
"dependencies": {
"ejs": "~3.3.1"
}
}

ejs: 3.3.2 // allowed Patch Version fix
ejs: 3.4.2 // not allowed Minor Version fix
ejs: 4.1.0 // not allowed Major Version fix

3. Equal ( = ) :The = (Equal ) sign in version dependency declarations is used to specify that you want to install the exact version of a package.

{
"dependencies": {
"ejs": "=3.3.1"
}
}

📚 Earlier Post:

What is NPM ? click below to know more 👇
https://medium.com/@omkarbhavare2406/what-is-npm-40dc291537d4

🔍 Coming up next:
Dependency vs DevDependency
Local & Global Package Installation:

Stay tuned for more insights into the world of JavaScript development! 🚀📦

--

--

Omkar Bhavare

Passionate developer, blogger, and problem solver. Crafting code, sharing insights, and building innovative projects. 🚀