So, what is nullish coalescence in JavaScript you ask? You’ve seen the double question mark “??” symbol in JavaScript and wondered what this is what action it performs. This is called Nullish Coalescence and it’s a very simple yet elegant feature in JavaScript or TypeScript. Let’s have a look.
In a nutshell, nullish coalescene checks the value of a variable and according to that value, it would either leave at that or assign it a default value. Kind of like an if-else conditioning. Simple right!
Let’s look at an example.
const details = {
name: "John",
age: 25
}
console.log(details.age); // THIS WOULD PRINT 25
console.log(details.weight); // THIS WOULD PRINT 'undefined'
Since the object details does not hold the key “weight”, it would return ‘undefined’ when called in line 7. And therefore, if we want some default value to get printed instead of ‘undefined’, we could use nullish Coalescence here. This even works for null as return type Like so:
console.log( details.weight ?? ‘70 kg’ ); // THIS WOULD PRINT ‘70 kg’ even if the return is ‘undefined’
So, basically “??” operand checks if the left side is either null or undefined, and if it is then it would go and assign the value set on the right side of the symbol “??”. That’s it!
TL;DR
If your defined variable could have a ‘null’ value or ‘undefined’ response stored in it and you would rather have a default value stored in it instead, then nullish Coalescence is the way to go.
var temp = ‘John’ ?? ‘some name’ // temp = John
var temp = undefined ?? ‘some name’ // temp = some name
var temp = null ?? ‘some name’ // temp = some name
Recent Posts
- Zonder Cruks Online Casino Veiligheid en beveiliging van spelers.1175
- Fortune Favors the Bold – Can You Lead Your Clucky Companion Down the Chicken Road & Cash Out Before
- Verfrissend Gokken met nieuwe online casino zonder cruks – Een Nieuwe Ervaring
- Elevate Your Play Find the best australian online casino Experiences with Lucrative Bonuses & Secure
- Lopebet’s Multi-Bet Options: How and When to Use Them
Recent Comments
Archives
- May 2026
- October 2025
- August 2025
- June 2025
- October 2024
- September 2024
- August 2024
- June 2023
- May 2023
- March 2023
- December 2022
- November 2022
- October 2022
- September 2022
- August 2022
- July 2022
- June 2022
- May 2022
- April 2022
- February 2022
- January 2022
- December 2021
- November 2021
- October 2021
- September 2021
- August 2021
- July 2021
Categories
- Angular
- AWS
- Backend Development
- Big Data
- Casino
- Cloud
- Database
- Deployment
- DevOps
- Docker
- Frontend Development
- GitHub
- Google Cloud Platform
- Installations
- Java
- JavaScript
- Linux
- MySQL
- Networking
- News
- NodeJS
- Online casino
- Operating System
- Post
- Python
- Python Flask
- Report
- Security
- Server
- SpringBoot
- Subdomain
- TypeScript
- Uncategorized
- VSCode
- Webhosting
- WordPress
Search
Recent Post
Zonder Cruks Online Casino Veiligheid en beveiliging
- 18 May, 2026
- 5 min read
Fortune Favors the Bold – Can You
- 15 May, 2026
- 6 min read
Verfrissend Gokken met nieuwe online casino zonder
- 14 May, 2026
- 6 min read