첨부 실행 코드는 나눔고딕코딩 폰트를 사용합니다.
728x90
반응형
728x170

■ 암묵적 타입 변환을 사용해 문자열을 구하는 방법을 보여준다.

 

▶ 예제 코드 (JAVASCRIPT)

// 숫자 타입
console.log(        0 + ""); // "0"
console.log(       -0 + ""); // "0"
console.log(        1 + ""); // "1"
console.log(       -1 + ""); // "-1"
console.log(      NaN + ""); // "NaN"
console.log( Infinity + ""); // "Infinity"
console.log(-Infinity + ""); // "-Infinity"

// 불리언 타입
console.log( true + ""); // "true"
console.log(false + ""); // "false"

// null 타입
console.log(null + ""); // "null"

// 심벌 타입
console.log(Symbol() + ""); // TypeError: Cannot convert a Symbol value to a string

// 객체 타입
console.log({}           + ""); // "[object Object]"
console.log(Math         + ""); // "[object Math]"
console.log([]           + ""); // ""
console.log([10, 20]     + ""); // "10,20"
console.log(function(){} + ""); // "function(){}"
console.log(Array        + ""); // "function Array() { [native code] }"
728x90
반응형
그리드형(광고전용)
Posted by icodebroker

댓글을 달아 주세요