본문 바로가기
끄적끄적

JS) number,infinity,-infinity,NaN

by 뇸뇸 nyomnyom 2022. 7. 28.

JS는

C언어처럼 숫자에 short, int, long,,,,등등 구별할 필요 없이

모든 숫자는 number로 통일

//number
const count = 17;
const size = 17.1;
console.log(`value: ${count}, type: ${typeof count}`);
console.log(`value: ${size}, type: ${typeof size} `);

그 외 알아둬야할 숫자와 관련된 종류

infinity : + 로 무한

-infinity : - 로 무한

NaN : 숫자가 아니다

//special numberic values : infinity,-infinity,NaN
//숫자인지 확인잘하기
//특별한 넘버 종류로 받아서 무한대가 되어 사용자에게 에러 발생
//그래서 그 값이 유효한 값인지 확인하고 사용하는게 중요

const infinity = 1/0 
const negativeInfinity = -1/0;
const nAn = 'not a number'/2;
console.log(infinity);
console.log(negativeInfinity);
console.log(nAn);

//bigInt
const bigInt =123456789n;
console.log(`vlaue: ${bigInt}, type: ${typeof bigInt}`);

댓글