{"id":13451734,"url":"https://github.com/tc39/proposal-nullish-coalescing","last_synced_at":"2025-09-28T21:31:19.566Z","repository":{"id":66034265,"uuid":"97854685","full_name":"tc39/proposal-nullish-coalescing","owner":"tc39","description":"Nullish coalescing proposal x ?? y","archived":true,"fork":false,"pushed_at":"2023-01-28T20:48:22.000Z","size":53,"stargazers_count":1233,"open_issues_count":0,"forks_count":23,"subscribers_count":74,"default_branch":"main","last_synced_at":"2024-09-27T03:24:41.030Z","etag":null,"topics":[],"latest_commit_sha":null,"homepage":"https://tc39.github.io/proposal-nullish-coalescing/","language":"HTML","has_issues":true,"has_wiki":null,"has_pages":null,"mirror_url":null,"source_name":null,"license":null,"status":null,"scm":"git","pull_requests_enabled":true,"icon_url":"https://github.com/tc39.png","metadata":{"files":{"readme":"README.md","changelog":null,"contributing":null,"funding":null,"license":null,"code_of_conduct":null,"threat_model":null,"audit":null,"citation":null,"codeowners":null,"security":null,"support":null,"governance":null}},"created_at":"2017-07-20T16:05:24.000Z","updated_at":"2024-09-20T12:17:50.000Z","dependencies_parsed_at":"2023-03-22T11:50:37.301Z","dependency_job_id":null,"html_url":"https://github.com/tc39/proposal-nullish-coalescing","commit_stats":null,"previous_names":[],"tags_count":0,"template":false,"template_full_name":null,"repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/tc39%2Fproposal-nullish-coalescing","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/tc39%2Fproposal-nullish-coalescing/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/tc39%2Fproposal-nullish-coalescing/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/tc39%2Fproposal-nullish-coalescing/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/tc39","download_url":"https://codeload.github.com/tc39/proposal-nullish-coalescing/tar.gz/refs/heads/main","host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":234563152,"owners_count":18853062,"icon_url":"https://github.com/github.png","version":null,"created_at":"2022-05-30T11:31:42.601Z","updated_at":"2022-07-04T15:15:14.044Z","host_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub","repositories_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories","repository_names_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repository_names","owners_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners"}},"keywords":[],"created_at":"2024-07-31T07:01:00.782Z","updated_at":"2025-09-28T21:31:19.275Z","avatar_url":"https://github.com/tc39.png","language":"HTML","funding_links":[],"categories":["HTML","JS"],"sub_categories":[],"readme":"# Nullish Coalescing for JavaScript\n\n## Status\nCurrent Stage:\n* Stage 4\n\n## Authors\n\n* Gabriel Isenberg ([github](https://github.com/gisenberg), [twitter](https://twitter.com/the_gisenberg))\n* Daniel Ehrenberg ([github](https://github.com/littledan), [twitter](https://twitter.com/littledan))\n* Daniel Rosenwasser ([github](https://github.com/DanielRosenwasser), [twitter](https://twitter.com/drosenwasser))\n\n## Overview and motivation\nWhen performing property accesses, it is often desired to provide a default value if the result of that property access is `null` or `undefined`. At present, a typical way to express this intent in JavaScript is by using the `||` operator.\n\n```javascript\nconst response = {\n  settings: {\n    nullValue: null,\n    height: 400,\n    animationDuration: 0,\n    headerText: '',\n    showSplashScreen: false\n  }\n};\n\nconst undefinedValue = response.settings.undefinedValue || 'some other default'; // result: 'some other default'\nconst nullValue = response.settings.nullValue || 'some other default'; // result: 'some other default'\n```\n\nThis works well for the common case of `null` and `undefined` values, but there are a number of falsy values that might produce surprising results:\n\n```javascript\nconst headerText = response.settings.headerText || 'Hello, world!'; // Potentially unintended. '' is falsy, result: 'Hello, world!'\nconst animationDuration = response.settings.animationDuration || 300; // Potentially unintended. 0 is falsy, result: 300\nconst showSplashScreen = response.settings.showSplashScreen || true; // Potentially unintended. false is falsy, result: true\n```\n\nThe nullary coalescing operator is intended to handle these cases better and serves as an equality check against nullary values (`null` or `undefined`). \n\n## Syntax\n*Base case*. If the expression at the left-hand side of the `??` operator evaluates to `undefined` or `null`, its right-hand side is returned.\n\n```javascript\nconst response = {\n  settings: {\n    nullValue: null,\n    height: 400,\n    animationDuration: 0,\n    headerText: '',\n    showSplashScreen: false\n  }\n};\n\nconst undefinedValue = response.settings.undefinedValue ?? 'some other default'; // result: 'some other default'\nconst nullValue = response.settings.nullValue ?? 'some other default'; // result: 'some other default'\nconst headerText = response.settings.headerText ?? 'Hello, world!'; // result: ''\nconst animationDuration = response.settings.animationDuration ?? 300; // result: 0\nconst showSplashScreen = response.settings.showSplashScreen ?? true; // result: false\n```\n\n## Notes\nWhile this proposal specifically calls out `null` and `undefined` values, the intent is to provide a complementary operator to the [optional chaining operator](https://github.com/TC39/proposal-optional-chaining). This proposal will update to match the semantics of that operator.\n\n## Prior Art\n* [Null coalescing operator](https://en.wikipedia.org/wiki/Null_coalescing_operator)\n\n## Specification\n* https://tc39.github.io/proposal-nullish-coalescing/\n\n## References\n* [TC39 Slide Deck: Null Coalescing Operator](https://docs.google.com/presentation/d/1m5nxTH8ifcmOlyaTmTuMAa1bawiGUyKJzQGlw-EVSKM/edit?usp=sharing)\n\n## Prior discussion\n* https://stackoverflow.com/questions/476436/is-there-a-null-coalescing-operator-in-javascript\n* https://esdiscuss.org/topic/proposal-for-a-null-coalescing-operator\n","project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Ftc39%2Fproposal-nullish-coalescing","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Ftc39%2Fproposal-nullish-coalescing","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Ftc39%2Fproposal-nullish-coalescing/lists"}