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
- Haaienjacht op de rollen de spanning van de chicken road game casino
- Překvapivé příležitosti a herní svět goldzino – pro radost a napětí
- Fast Payout Casinos Ireland.2848
- Spinsy Casino France comment jouer dans un casino en ligne moderne.2354
- Casino Yep PL Kompletny przewodnik po platformie kasyna online.85
Recent Comments
Archives
- June 2026
- May 2026
- October 2025
- October 2024
- September 2024
- August 2024
- June 2024
- January 2024
- November 2023
- October 2023
- September 2023
- August 2023
- 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
- 21
- Angular
- AWS
- Backend Development
- Big Data
- Blog
- Cloud
- crypto 20
- crypto 20.05
- crypto 21.05
- Database
- Deployment
- DevOps
- Docker
- fi
- Frontend Development
- GitHub
- Google Cloud Platform
- hu
- Installations
- it
- Java
- JavaScript
- Linux
- MySQL
- Networking
- News
- nl
- no
- NodeJS
- Online casino
- Operating System
- Post
- Python
- Python Flask
- Report
- Security
- Server
- SpringBoot
- Subdomain
- TypeScript
- Uncategorized
- VSCode
- Webhosting
- WordPress
Search
Recent Post
Haaienjacht op de rollen de spanning van
- 3 June, 2026
- 8 min read
Překvapivé příležitosti a herní svět goldzino –
- 3 June, 2026
- 7 min read
Fast Payout Casinos Ireland.2848
- 3 June, 2026
- 7 min read