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

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

#1

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

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


#2

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



#3

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.


#4

Sorry, no idea. I dont use pug.

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

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

locals.name
"john"

locals.last
"doe"