본문 바로가기

Programming/JavaScript

[JavaScript]변수에 할당 된 데이터 타입 조회 방법

728x90

JavaScript 데이터 타입 조회 방법

  • typeof “조회할 변수명”
    // 변수에 할당된 값 데이터 타입 체크 방법
    var abc;
    console.log(typeof abc);
    // undefined;

    abc = 10;
    console.log(typeof abc);
    // number;

    abc = 'Hello';
    console.log(typeof abc);
    // string;

    abc = true;
    console.log(typeof abc);
    // boolean;

    abc = null;
    console.log(typeof abc);
    // object;

    abc = Symbol();
    console.log(typeof abc);
    // symbol;

    abc = {};
    console.log(typeof abc);
    // object;

    abc = [];
    console.log(typeof abc);
    // object;

    abc = function () {};
    console.log(typeof abc);
    // function;