자바스크립트(JavaScript)
HTML 문서에 적용할 때 웹 사이트에 동적 상호작용을 제공할 수 있는 동적 프로그래밍 언어이다. (Dynamic Client-Side Scripting)
변수 자료형
String
- 문자열, 문자열을 변수로 나타내기 위함Number
- 숫자Boolean
- true/false에 대한 불리언 타입Array
- 배열 형태Object
- JavaScript의 모든 것은 객체이며, 변수에 저장이 가능하다.
아래와 같이 이용할 수 있다.
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 | // '//' 스크립트 창에서 주석을 표시할 수 있도록 한다. var x = 5; console.log(5); console.log("==========================\n"); /** 자바스크립트 내 변수 타입 **/ x = 1; x = 0.01; x = "Hello World"; x = "JavaScript"; x = true; // boolean x = false; // boolean x = null; // null x = undefined; // null 과 유사 /** - 자바스크립트 내 객체 타입 - 중괄호 내부에 name:value의 쌍으로 표시 **/ var book = { topic:"JavaScript", step:0, fat:true } /** 객체 내부 value 값 접근 4가지 방식 **/ console.log("(1) " + book); console.log(book); console.log("(2) " + book.topic); console.log("(3) " + book["step"]); console.log("(4) " + book['fat']); console.log("(5) " + book.fat); console.log("==========================\n"); /** 배열도 구현이 가능 **/ var numbers = [1, 2, 3, 4, 5]; console.log(numbers); console.log(numbers[0]); console.log(numbers[1]); console.log(numbers[2]); console.log("numbers length : " + numbers.length); numbers[0] = 1000; console.log(numbers[0]) var emptyArray = []; console.log("emptyArray length : " + emptyArray.length); console.log("==========================\n"); | cs |
console.log는 해당 브라우저 디버그 콘솔에서 확인할 때 이용하는 명령어이다. 출력된 값을 확인하면 아래와 같다.
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 | 5 ========================== (1) [object Object] { topic: 'JavaScript', step: 0, fat: true } (2) JavaScript (3) 0 (4) true (5) true ========================== [ 1, 2, 3, 4, 5 ] 1 2 3 numbers length : 5 1000 emptyArray length : 0 ========================== | cs |
'javascript' 카테고리의 다른 글
20180605 node.js & npm 개념 정립 및 설치 (0) | 2018.06.05 |
---|---|
20180420 CORS (수정 : 20191104) (0) | 2018.04.20 |
20180407 자바스크립트 조건 및 제어문 (0) | 2018.04.07 |
20180407 자바스크립트 연산 및 함수 (0) | 2018.04.07 |
20180330 form 태그를 통한 ajax 방식 (0) | 2018.03.30 |