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.

let name = firstName || 'Brian'

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 Reply

Your email address will not be published. Required fields are marked *