" ", ' ' - String 데이터 변수 선언 가능
let double = "double hello";
let single = 'single hello';
let little_double = 'little "double"';
let little_single = "little 'single'";
let remark_double = "remark \"double\"";
문자열에 " "를 쓰고 싶으면 ' '로 감싸고, ' '를 쓰고 싶으면 " "로 감싸야 한다.
" "만 사용하려면 문자열 안에 있는 " 앞에 \를 붙이면 사용할 수 있다.
Undefined - 아무것도 할당받지 않은 상태이다. 최초에 변수를 선언하고 값을 할당하지 않으면 이 상태로 진행된다.
NULL - 값이 없는 상태이다. 비어있는 상자와 같다.
let a = undefined;
let b = null;
Object - 여러 속성을 하나의 변수에 저장할 수 있는 데이터 타입
let employee= {};
employee.name = "Lee";
employee.department= "Computer";
employee.age = 26;
let employee2= {};
employee2["name"] = "Lee";
employee2["department"] = "Computer";
employee2["age"] = 26;
let employee3= {
name : "Lee",
department: "Computer",
age : 26
}
위와 같이 다양한 형태로 object 구성할 수 있다.
Array - 배열
let arr = ["Spring", "Summner", "Fall", "Winter"];
let arr2 = [3, 24, 5, 12];
let arr3 = ["Winter", 45, undefined];
let arr4 = [employee, employee2, employee3];
let arr5 = [];
arr5[1] = 39;
arr5[3] = 8;
arr5.push(1);
arr5.push(26);
문자열, 숫자, Object 등을 배열로 선언할 수 있다. arr5 처럼 빈 배열을 만들고 원하는 곳에 값을 집어넣을 수 있다.
push는 마지막에 값을 추가하는 메소드이다.
Boolean - 참, 거짓을 나타내는 데이터 타입
let x = 6;
let y = 12;
let bool = true;
console.log(x < y);
console.log(x > y);
결과는 true, false 이다.
typeof - 변수의 타입을 알려주는 함수이다.
console.log(typeof a);
console.log(typeof employee);
console.log(typeof arr2);
결과는 아래와 같다.
undefined
object
object
배열도 object로 반환한다.
'프로그래밍 > Java Script' 카테고리의 다른 글
Java Script - 연산자 Operator (0) | 2022.12.05 |
---|---|
Java Script - 64bit 부동 소수점 (0) | 2022.12.05 |
Java Script - 변수 var, let, const (0) | 2022.12.03 |
Java Script - 콘솔, 주석 console, comment (0) | 2022.12.02 |
Java Script - 기본 설정 (0) | 2022.12.02 |