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.

%MINIFYHTML3e976415847e95bd1c8e1c1755d108a223%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