JS Using OR for Default Values

The double pipes (||) which represents the logical OR operator, can also be used to set a default value on a variable.

%MINIFYHTMLee54a640820548dc41d8747f452c80cf25%
let name = firstName || 'Brian'
Code language: JavaScript (javascript)

In the case above, if firstName is null, then the default value of ‘Brian’ will be added.

1 thought on “JS Using OR for Default Values

Leave a Comment