1) null: Object type but empty or no existence

2) undefined: undefined type, a variable has been declared but the value of this has not defined

3) NaN: Not a Number

4) null !== undefined but null == undefined  // type은 같지 않으나 존재하지 않는건 같음

'JavaScript' 카테고리의 다른 글

Closure Function  (0) 2020.12.05
Recursion Function (재귀함수)  (0) 2020.12.05
Template Literals  (0) 2020.12.03
정규식  (0) 2020.12.03
Prototype  (0) 2020.12.03

자바스크립트에서 문자와 변수를 표현하는 방법

let s = {
  firstName: "Harry",
  lastName: "Smith"
}

console.log(s.firstName, s.lastName);
console.log("My name is ", s.firstName, "     ", s.lastName);
console.log("Hi", "My name is ", s.firstName, s.lastName);

// + 기호를 이용한다
console.log("Hi, My name is " + s.firstName + " " + s.lastName);

// 백태그(`)를 이용한 템플릿 사용
console.log(`Hi, I'm ${s.firstName} ${s.lastName}`);

'JavaScript' 카테고리의 다른 글

Recursion Function (재귀함수)  (0) 2020.12.05
null Vs. undefined Vs. NaN  (0) 2020.12.04
정규식  (0) 2020.12.03
Prototype  (0) 2020.12.03
즉시 실행 함수(IIFE: Immediately Invoked Function Expression)  (0) 2020.12.02

1. 정규식 생성 방식

var reg1 = /a/;        // constant
var reg2 = new RegExp(“a”);       //changing

2. Symbols

.   : any single character, except line breaks
*   : 0 or more matched
+   : 1 or more matched
?   : 0 or 1 matched
^   : begin with string
$   : end with string

3. Characters

\d   : any single digit matched
\w   : any word character(alphanumeric & underscore)
[XYZ]  or [A-Z]  : any single character matched from within the brackets. 
[XYZ]+   : 1 or more matched from within the brackets
[^A-Z]   : ^ is negation. nothing matched A-Z

4. Flags

g   : global search
I   : case intensive search

'JavaScript' 카테고리의 다른 글

null Vs. undefined Vs. NaN  (0) 2020.12.04
Template Literals  (0) 2020.12.03
Prototype  (0) 2020.12.03
즉시 실행 함수(IIFE: Immediately Invoked Function Expression)  (0) 2020.12.02
Callback, Promise, Observable and Async/await  (3) 2020.12.02

JavaScript는 prototype 기반의 언어이다. JavaScript는 상속이 없으나 최근 class 도입에 따라 가능하게 되었다. 그러나 prototype을 활용한 상속의 구현이 여전히 더 많이 사용된다.

function School(address) {
  this.name = "Seneca";
  this.address = address;
}

var mySchool = new School("Finch");
console.log(mySchool.name);   // Seneca
console.log(mySchool.address);   // Finch

What if 객체가 10개 100개 그 이상 생성된다면, 메모리가 갖게되는 수도 그만큼 늘어날 것이다. 이를 prototype을 통한 접근으로 상속을 통해 해결한다.

/* 함수를 선언하게 되면 (1)생성자 기능부여, (2)prototype object 생성이 일어난다 */
function School(){}

// (1)생성자 기능 - 함수만 가능
var mySchool = new School();

// (2) prototype object 생성
/* 함수가 생성되면서 prototype object가 생성된다. */
/* 함수는 prototype 프러퍼티를 통해 prototype object에 접근한다. */
School.prototype.name = "Seneca";
/* prototype object는 디폴트로 constructor()와 __proto__ 를 갖는다.(prototype link 라함) */
/* prototype 프러퍼티를 통해 prototype object에 속성을 추가할수 있다. */
/* 객체를 생성하게 되면, 생성된 객체는 __proto__ 를 갖는다. */
var mySchool = new School();
/* mySchool 의 __proto__ 는 School의 prototype object 를 가리키며, 이를 통해 데이터를 찾게된다. */
/* 마찬가지로 School 의 __proto__ 도 상위 prototype object (Object())를 탐색하게된다. */
/* 이렇게 상위 prototype으로 연결된걸 prototype chain 이라 한다. */

prototype 관계도

** prototype 관계도 **

Simple 예제

function School(address) {
// 객체 생성시 추가
	this.address = address;
}

// 상속받아서 사용
School.prototype.name = "Seneca";

var mySchool = new School("Finch");
console.log(mySchool.name);
console.log(mySchool.address);

var yourSchool = new School("York");
console.log(yourSchool.name);
console.log(yourSchool.address);

+ Recent posts