Why javascript console.log(1 + + " " + 3); sentence returns 4 and not "1 3"? -


when statement console.log(1 + + " " + 3); executed in chrome console, result 4 , not "1 3" expect.

can please explain why case?

this behaviour called coercion.

in case unary plus operator + converts number expression @ right. if cannot parse particular value, evaluate nan.

+ " " //--> coerced 0 

you can see coercion examples in gist: javascript coercion


Comments

Popular posts from this blog

c# - Validate object ID from GET to POST -

node.js - Custom Model Validator SailsJS -

php - Find a regex to take part of Email -