Skip to content

Commit

Permalink
Add nullish coalescing operator example, see phetsims/density-buoyanc…
Browse files Browse the repository at this point in the history
  • Loading branch information
samreid committed Aug 16, 2024
1 parent b8ea209 commit fa8a3b2
Showing 1 changed file with 9 additions and 0 deletions.
9 changes: 9 additions & 0 deletions js/wilder/model/WilderModel.ts
Original file line number Diff line number Diff line change
Expand Up @@ -184,6 +184,15 @@ class WilderModel implements TModel {
hardAssert( forest === 5 );
hardAssert( leaf === 1024 );

// Nullish Coalescing Assignment (??=)
let helloWorld;
helloWorld ??= 'Hello, World!';
hardAssert( helloWorld === 'Hello, World!' );

helloWorld = 'Hi again!';
helloWorld ??= 'Hello, World!';
hardAssert( helloWorld === 'Hi again!' );
console.log( 'helloWorld: should be Hi again!', helloWorld );

type SecretSelfOptions = {
secret?: number;
Expand Down

0 comments on commit fa8a3b2

Please sign in to comment.