티스토리 뷰

🌈 JavaScript

Number 객체

James Wetzel 2024. 7. 4. 16:31
728x90
반응형
console.log(Number(100));
// > 100

console.log(Number("100"));
// > 100

console.log(Number(""));
// > 0

console.log(Number("test"));
// > NaN

console.log(isNaN(Number("test")));
// > true

console.log(isNaN(Number("test")) ? 0 : Number(100));
> 0
728x90
반응형