What is meaning of the following variable declaration in a pug template engine

I do not understand the “locals” and using OR operator

block content
-var err = locals.err || [];
-var user = locals.user || {};

The OR operator is used to initialize a variable with some pre-defined default value, or if there’s none, your own initial value.

something = null; 
myvar = something || 42;    // will be initialized to 42 since something is null 

// but if something has a value
something = 99;
myvar = something || 42;    // will be initialized to 99, which is the value of the something variable

1 Like

Thank you for your help. Do you happen to know what locals.user is referring to, here? No variable named locals was passed to the view from the controller. Im not getting it.

Sorry, no idea. I dont use pug.

Are you using JS objects in your pug template? something like this:

locals = {name:'john', last:'doe'}