DEV Community

loading...

Implicit Conversion JavaScript

mubasshir00 profile image Mubasshir Ahmed ・1 min read

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

Discussion (1)

pic
Editor guide
Collapse
nahidestes profile image
Nahid Estes

Thanks a lot....