์๋ฐ์คํฌ๋ฆฝํธ๋ ํ์ ์ด ์ ์ฐํ ์ธ์ด์ด๋ค. ๊ทธ๋ฌ๋ฉด ํ๋ณํ์ ์ด๋ป๊ฒ ํด์ผํ๋?
๋จผ์ , ๊ธฐ๋ณธ์ ์ผ๋ก ์๋ฐ์คํฌ๋ฆฝํธ์ ํ์ ์ ์๋์ ๊ฐ์ด ์กด์ฌํ๋ค.
์์ํ์
1. ์ซ์ (number)
2. ๋ฌธ์์ด (string)
3. ๋ถ๋ฆฌ์ธ (boolean)
4. undefined
5. symbol -> ES6 ๋ฒ์ ์์ ์๋กญ๊ฒ ์ถ๊ฐ๋จ
๊ฐ์ฒดํ์
6. object
ํ๋ณํ
์ซ์๋ณํ
Number()
Number()์ ์ ์ํ๊ณผ ์ค์ํ์ ์ซ์๋ก ๋ณํํ๋ค.
Number("12345") // 12345 Number("10"*10) // 100
parseInt()
parseInt()๋ ์ ์ํ์ ์ซ์๋ก ๋ณํํ๋ค.
parseInt(โ123โ) //123 parseInt(123.35) //123 parseInt(0033); //0์ผ๋ก ์์ -> 8์ง์๋ก ์ธ์ง : 27 parseInt(0x1b); //0x๋ก ์์ -> 16์ง์๋ก ์ธ์ง : 27 parseInt(โ 2โ); //2 parseInt(โ 3rโ); //3 parseInt(โ ใ
ใ
โ); //NaN
parseFloat()
parseFloat()๋ ๋ถ๋ ์์์ ์ ์ซ์๋ก ๋ณํํ๋ค.
parseFloat(โ^123โ); //NaN parseFloat(โ123.123456โ); //123.123456 parseFloat(โ 123.123456โ); //123.123456 parseFloat(โ a123.123456โ); //NaN
๋ฌธ์์ด๋ณํ
String()
String()์ ๋ฌธ์ํ์ ์ผ๋ก ๋ณํํ๋ค.
String(123); //โ123" String(123.456); //โ123.456"
toString()
toString()์ ๋ฌธ์ํ์ ์ผ๋ก ๋ณํํ๊ณ , ์ธ์๋ก ๊ธฐ์๋ฅผ ๋ฃ์ ์ ์๋ค.
var num = 100; num.toString(); //โ100" num.toString(2); //โ1100100" num.toString(8); //โ144" var boolT = true; var boolF = false; boolT.toString(); //โtrueโ boolF.toString(); //โfalseโ
toFixed()
toFixed()์ ๋ฌธ์ํ์ ์ผ๋ก ๋ณํํ๊ณ , ์ธ์๊ฐ๋งํผ ๋ฐ์ฌ๋ฆผํ ์ ์๋ค.
var num = 123.456789; var roundOff = 99.987654; num.toFixed(); //โ123" num.toFixed(0); //โ123" num.toFixed(2); //โ123.46" num.toFixed(8); //โ123.45678900" roundOff.toFixed(2); //โ99.99" roundOff.toFixed(0); //โ100"
๋ถ๋ฆฐํ์ ๋ณํ
Boolean()
Boolean()์ ๋ค๋ฅธ ์๋ฃํ์ ๋ถ๋ฆฐํ์ ์ผ๋ก ๋ณํํ ์ ์๋ค.
Boolean(100); //true Boolean(โ1โ); //true Boolean(true); //true Boolean(Object); //true Boolean([]); //true Boolean(0); //false Boolean(NaN); //false Boolean(null); //false Boolean(undefined); //false Boolean( ); //false
'FE > JavaScript' ์นดํ ๊ณ ๋ฆฌ์ ๋ค๋ฅธ ๊ธ
[JavaScript] ์๋ฐ์คํฌ๋ฆฝํธ slice ๋ฉ์๋ (0) | 2024.03.04 |
---|---|
[JavaScript] ์๋ฐ์คํฌ๋ฆฝํธ Join ์ฌ์ฉ๋ฒ (0) | 2024.03.03 |
[JavaScript] ์๋ฐ์คํฌ๋ฆฝํธ ์ฌ๋ฆผ, ๋ด๋ฆผ, ๋ฐ์ฌ๋ฆผ(Math ๋ฉ์๋) (0) | 2024.03.01 |
[JavaScript] ์๋ฐ์คํฌ๋ฆฝํธ reduce ํจ์ ์ฌ์ฉ๋ฒ (0) | 2024.02.28 |
[JavaScript] ๋ฆฌ์คํธ ์ถ๊ฐํ๊ธฐ (0) | 2024.02.28 |