javascript - Assigning data from an array, or what? -


i came across line , i'm unsure how does. data portion json object , later on, "myarray" variable used assign new variables array.

the "myitems" object used iterate through .map function on objects in data object. have no idea how gets assigned through code below:

var myitems = data || [], myarray; 

it declares 2 global variables myitems , myarray. items assigned data if data not undefined, if data undefined assigns empty array myitems.

the || operator can used during assignment due truthy or falsey nature of variables in javascript.

several values equate false in javascript such empty string "" or undefined. others such string literal != "" (example "test") , objects equate true. when used in assignment section of code proceeding || not evaluated if first expression equates true.

this link gives better description of truthy , falsey.


Comments

Popular posts from this blog

php - Why I am getting the Error "Commands out of sync; you can't run this command now" -

linux - Does gcc have any options to add version info in ELF binary file? -

java - Are there any classes that implement javax.persistence.Parameter<T>? -