What is the meaning of adding a + in js? [duplicate]

I have a condition in reactjs that starts with


Why do we write + ?

1 Answer

Is a forced conversion to number

const str = '1'
const bool = false
const fail = 'isNan?'

const num = +str
const numBool = +bool
const numFail = +fail

console.log(typeof num, typeof numBool, numFail)

Archive from: https://stackoverflow.com/questions/59070213/what-is-the-meaning-of-adding-a-in-js

Leave a Reply

Your email address will not be published. Required fields are marked *