'typeof'에 해당되는 글 1건

  1. 2008.12.01 | [javascript] typeof 연산자

[javascript] typeof 연산자

WEB2.0/ExtJS | 2008. 12. 1. 11:27
Posted by 시반

typeof 연산자는 형식 정보를 문자열로 반환하며 "Number", "String", "Boolean", "Object", "Function", "undefined"라는 6가지 형식을 반환할 수 있습니다.

선택적인 요소로 typeof 구문에 괄호를 사용할 수도 있기에 다음 둘 중 한 가지 방법으로 사용할 수 있습니다.

1. typeof operand
2. typeof (operand)

 

if ( typeof(object) != "Object" ) {

alert('객체가 아닙니다.');

}

if ( typeof 'AAA'  != 'Number' ) {

alert('숫자가 아닙니다.');

}

 

또다른 예를 들어 우리가 이런 변수를 정의했다고 해봅시다.

  • var myFun = new Function("5+2");
    var shape="round";

    var size=1;

    var today=new Date()
typeof는 이 변수들에 대해서 다음과 같은 결과를 반환할 것입니다. 
  • typeof myFun is function
    typeof shape is string

    typeof size is number

    typeof today is object

    typeof dontExist is undefined

truenull 키워드에 대해서 typeof 연산자는 다음과 같은 결과를 반환합니다.

  • typeof true is boolean
    typeof null is object

수와 문자열에 대해서 typeof 연산자는 다음과 같은 결과를 반환합니다.

  • typeof 62 is number
    typeof 'Hello world' is string

속성 값에 대해서 typeof 연산자는 속성이 포함하고 있는 값의 형식을 반환합니다.

  • typeof document.lastModified is string
    typeof window.length is number
    typeof Math.LN2 is number

메소드와 함수에 사용하면 typeof 연산자는 다음과 같은 결과를 반환합니다.

  • typeof blur is function
    typeof eval is function
    typeof parseInt is function
    typeof shape.split is function

미리 정의된 개체들에 대해서 typeof 연산자는 다음과 같은 결과를 반환합니다.

  • typeof Date is function
    typeof Function is function
    typeof Math is function
    typeof Option is function
    typeof String is function
 
블로그 이미지

시반

시반(詩伴)이란 함께 시를 짓는 벗이란 뜻을 가지고 있습니다. 함께 나눌수 있는 그런 공간이길 바라며...

카테고리

분류 전체보기 (233)
개발 이야기 (73)
WEB2.0 (57)
DB2 (24)
MySQL (6)
오라클 (26)
기타 (44)
취미 (0)
잡담 (2)