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.

%MINIFYHTMLc2530c4051ac073713284100dc504f8623%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.

About Author /

1 Comment

Leave a Comment

Your email address will not be published.

Start typing and press Enter to search