ES5 ? ES6?

Zoey·2022년 1월 23일
0

ES5는 뭐고 ES6는 뭘까?

우선 ES는 ecmascript의 약자로 자바스크립트의 표준, 규격이라고 볼 수 있다.
뒤에 붙어있는 숫자는 버전을 뜻하는데 ES5는 2005년 출시, ES6는 2016년 출시로 사이에 많은 기간차이가 있다. ES6이후에는 매년 업데이트가 되고있는 반면 5,6는 기간차이만큼 달라진 점이 많다.


문법적으로 달라진 걸 살펴보자 !

  • let, const가 추가되었다.
    기존에 쓰이던 var는 호이스팅문제로 전역,지역의 차이가 모호한 점이 있었고 그것이 아주 때론 치명적이였다. 그래서 새로 나온 게 바로 let과 const!
    let은 변수를 선언할 때 쓰이고 , const는 상수를 선언할 때 쓰인다
  • 화살표 함수의 등장
    여러 코드들을 보면 => 이렇게 생긴 함수를 본 적이 있을 것이다. 그것이 바로 화살표 함수 ! 기존의 function을 간소화시킨 모양이라고 생각하면 된다.
    단, 기존의 함수와 this 바인딩이 다르다!
  • default parameter
    기존 함수에는 초기값을 설정하려면 내부에 로직을 추가해야했으나, 이제는 간편하게 작성할 수 있게 됐습니다
//ES5
var height = function(height){
	var heigth = height || 180
}
//ES6
const height = function(height = 180){

} 
  • Template literal 추가
    백틱(``) 으로 사용하면 되는데 이렇게 사용한다
//ES5
var first_name = "zoey"
var last_name = "An"
var me = "제 이름은" +last_name+ +first_name+ "입니다."
//ES6

const me = `제 이름은 ${last_name} ${first_name} 입니다.`
  • multi line string

여러 줄이 되었을 경우 \n + 으로 줄띄움을 해줬어야 했으나 백틱``을 사용하면 문제없습니다!

//ES5
var Lorem = "Lorem Ipsum is simply dummy text of the\n+ printing and typesetting industry. Lorem Ipsum has been \n +  the industry's standard dummy text ever since the 1500s, when an unknown printer took a galley of type and\n +  scrambled it to make a type specimen book. It has survived not only five centuries, but also the leap into\n + electronic typesetting, remaining essentially unchanged. It was popularised in the 1960s with the \n +release of Letraset sheets containing Lorem Ipsum \n +passages, and more recently with desktop publishing \n +software like Aldus PageMaker including versions of Lorem Ipsum."

//ES6
const Lorem = `Lorem Ipsum is simply dummy text of the printing and typesetting industry. Lorem Ipsum has been the industry's standard dummy text ever since the 1500s, when an unknown printer took a galley of type and scrambled it to make a type specimen book. It has survived not only five centuries, but also the leap into electronic typesetting, remaining essentially unchanged. It was popularised in the 1960s with the release of Letraset sheets containing Lorem Ipsum passages, and more recently with desktop publishing software like Aldus PageMaker including versions of Lorem Ipsum.`

  • 클래스
    객체 생성 방식 중 하나입니다.
  • 모듈
    모듈이란 재사용하기 위한 코드 조각입니다. 세부사항은 캡슐화 시키고, API부분만 외부에 노출시킵니다
<script type="module" src="./app.mjs"></script>

더 많은 것들은

출처 : https://hbsowo58.tistory.com/407

여기 블로그를 참조하자!

profile
한 걸음씩 단단하게 !

0개의 댓글