Why are false values ​​and empty lines in the array displayed as [Object Object] in Mustache?

I cannot do mustache.js to download from github to jsfiddle.net, so I downloaded the file and tried on the local computer:

var output = Mustache.render( "{{#arr}} {{.}} \n{{/arr}}", { arr : [1, 3.12, NaN, Infinity, -Infinity, 0, -0, null, "", " ", "0", true, false, undefined, "hee"] } ); console.log(output); 

to my surprise, false values ​​are displayed as [object Object] , although white papers say that {{.}} for string . The numbers 1 and 3.12 actually turned out to be beautiful. Note that this is a primitive number type, not a string. The console.log panel shows:

  1 3.12 [object Object] Infinity -Infinity [object Object] [object Object] [object Object] [object Object] 0 true [object Object] [object Object] hee 

I wonder why false values, including the valid string "" , are displayed as [object Object] ?

If I do this arr : ["ha", "hee", "", "wah"] , then all the lines are fine, but the third is [object Object] .

If it works for "ha" , why doesn't it work for "" ? If it works for 3.12 , why doesn't it work for 0 ? Maybe this can make sense if it works for all primitive values?

(I tried using Handlebars again and all values ​​appeared except null , undefined and false )

+6
source share

Source: https://habr.com/ru/post/946147/


All Articles