javascript - core - 변수02

yj k·2023년 4월 14일

javascript

목록 보기
2/18

2. dynamically-typed-language

자바스크립트는 동적타입언어이다.

  • 데이터 타입을 사전에 선언하지 않는다.
  • 변수 선언이 아니라 할당에 의해 타입이 결정 되며 재할당에 의해 동적으로 변수의 타입이 변화할 수 있다.

typeof : 데이터 타입을 확인해주는 연산자


var test;
console.log(typeof test);       // undefined

test = 1;
console.log(typeof test);       // number

test = 'JavaScript';
console.log(typeof test);       // string

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

test = null;
console.log(typeof test);       // object
// 자바스크립트의 첫 번째 버전의 버그이지만 기존 코드에 영향을 줄 수 있어 아직까지 수정 되지 못하고 있다.

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

test = {};  // 객체
console.log(typeof test);       // object

test = [];  // 배열
console.log(typeof test);       // object

test = function(){}; // 함수
console.log(typeof test);       // function

0개의 댓글