
자바스크립트에는 다섯가지 가장 기본적인 데이터 타입이 있다.
4, 9.3, -10“Hello World”, “43”true, falsenullundefinednull 은 변수를 선언하고, 'null'이라는 빈 값을 할당한 경우, undefined 는 변수 선언만 하고 값을 할당하지 않은 것이다. 즉, 자료형이 결정되지 않은 것이다. (선언하지 않은 변수도 콘솔에는 undefined라고 뜨지만 그 값을 가진 것은 아니다.)
null의 빈 값은 숫자의 경우 0, 문자열의 경우 '', 객체형데이터(array, object)의 빈 값을 의미한다. 이들 모두는 if문에서 false로 형 변환 된다.
출처: https://enarastudent.tistory.com/entry/null과-undefined의-차이 [Coding Story]
"she said \"goodbye!\" "
String 안에 따옴표를 넣고 싶을때는 따옴표 앞에 backslash( \ )를 추가하면 된다.
“hello world”.length // 9
글자수 세는 방법
“hello”[1] // “e”
index 계산하기, index는 0부터 시작한다.
var yourVariableName = yourValue;
variables : 데이터 컨테이너
var age;
age = undefined
// 공간은 있는데 정의가 안됨.
var name = “Rusty”;
var secretNumber = 73;
var isAdorable = true;
var : 범적으로 활용가능let : 한번 declare된 것은 다시 declare 할 수 없다. ressigned 가능. Block scoped.const : 변경불가 push 가능 reassigned 불가능 Block scoped.clear() : 콘솔 창 정리하는 method
alert() : 알림창 method
console.log() : JS 콘솔에 프린트되는 것. User에게는 보이지 않는다.
prompt() : User에게 질문창을 띄우기.
ex) var userName = prompt(“what is your name?");
userName = User의 인풋