Asked 7 years ago
11 Jan 2017
Views 2071
web-api

web-api posted

DADDY

DADDYYYYYYY
Phpworker

Phpworker
answered Nov 30 '-1 00:00


[] = array
{} = object
[]+{} = "[object object]"
ok got that now surprise come
{}+[] = 0
why {}+[] = 0 in JavaScript ? when all have stable behavior than why {}+[] = 0 ? it should be array or object
shyam

shyam
answered Nov 30 '-1 00:00


 [5,6,8,7][1,2] = 8 


i dont get why [5,6,8,7][1,2] = 8 in JavaScript ?

i find it crazy
Rasi

Rasi
answered Nov 30 '-1 00:00

null have really crazy behaviour
see

parseInt(null); // NaN 
null + null; //0 
null + 0; // 0


parseInt should return null or 0 For parseInt(null) in JavaScript but it return Not a Number (NaN)

null + null should be null . its like 0+0 but it return 0 , why ?
again null+0 should be null but it return again 0 , why ?

Why JavaScript does not make null+null = null like it does 0+0 =0 ?

0*null // null 
0*NaN // NaN


In JavaScript , if multiplication 0 to any one value make it 0 Than why NaN*0 is NaN , not Zero(0)
correct me if i am wrong
jessica

jessica
answered Nov 30 '-1 00:00

why JavaScript return value for same type of coding ?


{name : ["javascript","expert"] } // return object with array 
{name : {"javascript","expert"} } // return last value of inner obejct 


i mean object have array than it return proper object in JavaScript
but if object have another object than it return last value of inner object . is it crazy in JavaScript ?
{{ }} it should return proper object instead of last value of inner object why it is so in JavaScript ?



Mitul Dabhi

Mitul Dabhi
answered Nov 30 '-1 00:00

One crazy output of JavaScript


console.log(++[[]][+[]]+[+[]])

any guess what output should be for above
++[[]][+[]]+[+[]] = 10
it will output 10
isnt JavaScript crazy ?

ravi

ravi
answered Nov 30 '-1 00:00

what happen if string multiply to number in JavaScript ?
in JavaScript number in string format behave like number . all math operation will work on it like number,

console.log("4"*0);//0
console.log("4"*5);//20


it means if number is define like string . still its number , lets test what is typeof "4" in JavaScript


console.log(typeof "4");//String

"number" is still string not number but behave like number

from above result we can conclude that string can multiply with number and give good result.than see below test:

console.log("how_do_you_know_i_am_no_number"*"10");//NaN

so "string" work like really string



so i think when we define string with value of number and try some math operation it check is it number if yes than do the operation as number either consider it as string.
Post Answer