DEV Community

Mubasshir Ahmed
Mubasshir Ahmed

Posted on

Implicit Conversion JavaScript

res = '6' + 2 = output : '62' ( String + Number = String )
res = '6' + true = output : '6true' (string + boolean = string boolean )
res = '6' + null = output : '6null' (String + null = String null)
res = null + '6' = output : 'null6' (null + String = null String)
res = null + null = output : 0 ( null + null = 0)

res = '6' - '2' = output : 4 (String - String = Number)
res = '6' - 2 = output : 4 (String - Number = Number )
res = '6' * 2 = output : 8 (String * Number = Number )
res = '4' / 2 = output : 2 (String / Number = Number )

res = 'b' + 'a' + + 'a' + 'a' = output : baNaNa
(String + String + NaN + String + String)
res = ++ 'a' = output : NaN (NaN + String = NaN)

Boolean ('Hello') => true
Boolean (NaN) => False
Boolean ('NaN') => True
Boolean (null) => False

Top comments (1)

Collapse
 
nahidestes profile image
Nahid Estes

Thanks a lot....