
자바스크립트 기본 파일 형식 : .js
console.log('Hello world');
console.log('Hello', 'World');
var name; // var는 거의 사용안한다.
// 변수 선언
name = 'Jake';
// 변수 할당(자바의 초기화와 같은 의미)
let user = 'Ryan';
// 변수 선언과 할당을 동시에
// 상수는 선언만 하는 것도 가능
// 이 경우 변수 값은 'undefined'
2) 상수 : const
const age = 25;
// 상수는 선언만 하는게 불가능 → 할당이 반드시 이루어져야함\
3) 변수 명명 규칙
① 영어를 사용하며 문자와 숫자 모두 사용할 수 있다.
② 가능한 특수 기호 : _ $ 만 가능
③ 숫자로 시작 불가
④ 키워드는 변수명 사용 불가
1) camelCase -> 대부분의 언어에서 사용(자바스크립트도 마찬가지)
2) snake_case - 소문자만 사용 (파이썬)
3) PascalCase -> C# 마이크로소프트 계열의 언어에서 사용
자바스크립트의 데이터타입(Data Types)
1) Number (숫자)
2) String (문자열)
3) Boolean (불리언, 참,거짓)
4) undefined (언디파인드)
5) null (널)
6) symbol (심볼)
7) object(객체)
# escape 문자 : 자바와 동일
\n, \t, \\
1) Number (숫자)
const age = 32; const temperature = -10; const pi = 3.14; console.log(typeof age); //typeof -> 타입확인 console.log(typeof temperature); console.log(typeof pi); // ----------결과값 //number //number //number
2) String (문자열)
const name = 'jake'; const jake = "제이크" console.log(typeof name); console.log(jake); //----------결과값 // string // 제이크
3) Boolean (불리언, 참,거짓)
const isTrue = true; const isFalse = false; console.log(typeof isTrue); console.log(typeof isFalse); //----------결과값 //boolean //boolean
4) undefined (언디파인드) - 그냥 비어있는 값
let noinit; console.log(noinit); //----------결과값 //undefined
5) null (널) - 개발자가 명시적으로 없는 값으로 초기화
let noinit2 = null; console.log(typeof noinit2); //----------결과값 // object(버그)
6) symbol (심볼) : 유일무이한 값
const test1 ='1'; const test2 ='1'; console.log(test1 === test2); const symbol1 = Symbol('1'); const symbol2 = Symbol('1'); // 대문자 조심 console.log(symbol1 === symbol2); //----------결과값 // false // true
7) object(객체)
① Map타입 (key : Value)
const dictionary = { //자바 collection이랑 같은 개념 red : '빨간색', orange : '주황색', yellow : '노란색' }; console.log(dictionary) console.log(dictionary['red']); console.log(typeof dictionary); //----------결과값 // { red: '빨간색', orange: '주황색', yellow: '노란색' } // 빨간색 // object
② Array타입(배열)
const dictionary2 = [ '빨간색', '주황색', '노란색', ]; console.log(dictionary2) console.log(dictionary2[0]); dictionary2[0] = '검은색' // 배열 변경도 가능 console.log(dictionary2) console.log(typeof dictionary); //----------결과값 // [ '빨간색', '주황색', '노란색' ] // 빨간색 // [ '검은색', '주황색', '노란색' ] // object
VS Code 단축키 일부