목차

  1. 변수
  2. 연산자
  3. 조건문
  4. 반복문

1. 변수

자료형 설명 예시
number 숫자 (정수, 실수) 10, 3.14
string 문자열 "홍길동", 'hello'
boolean 참/거짓 true, false
array 배열 ['서울', '대전']
object 객체 {name: '홍길동', age: 25}
null 비어 있는 값 null
undefined 정의되지 않은 값 undefined

변수 선언 방식

var a = 1;       // ES5 방식 (지양)
let b = 2;       // 값 변경 가능
const c = 3.14;  // 상수, 값 변경 불가

예제 출력 (브라우저 문서 출력)

let var1 = 1;
let var3 = true;
let var5 = "hello";
let var7 = null;
let var8;

document.write('var1 : ' + var1 + ', type : ' + typeof var1 + '<br>');
document.write('var3 : ' + var3 + ', type : ' + typeof var3 + '<br>');
document.write('var5 : ' + var5 + ', type : ' + typeof var5 + '<br>');
document.write('var7 : ' + var7 + ', type : ' + typeof var7 + '<br>');
document.write('var8 : ' + var8 + ', type : ' + typeof var8 + '<br>');

2. 연산자

종류 예시 설명
문자열 연산자 + 문자열 결합
산술 연산자 +, -, *, /, %, ++, -- 사칙연산 및 증감
비교 연산자 <, >, <=, ==, ===, != 조건 비교
논리 연산자 &&, `
조건 연산자 (조건) ? 참 : 거짓 삼항 조건 연산
대입 연산자 =, +=, -=, *= 값을 변수에 저장 또는 조합

예시

let x = 10;
let y = 5;
let result = (x > y) ? "x가 크다" : "y가 크다";
console.log(result); // "x가 크다"