HTML.CSS.JS/JS

[JS] 형변환

congs 2023. 4. 14. 09:53

형변환

 

문자 -> 숫자 string to number

number()

parseInt()

perseFloat()

 

숫자 -> 문자 number to string

123.toString()

(12.3).toString()

 

문자 -> 불리언 string to boolean

Boolean("true")

 

불리언 -> 문자 boolean to string

String(true)

 

숫자 -> 불리언 number to boolean

Boolean(1) => true로 반환

Boolean(0) => false로 반환

 

불리언 -> 숫자 boolean to number

Number(true) => 1로반환

Number(false) => 0으로 반환