var, let, const 차이
https://velog.io/@bathingape/JavaScript-var-let-const-차이점
//1. let은 한번 선언된 변수에 다시 새롭게 선언할 수 없어요.
let num2 = 20;
num2 = "hello";
let num2 = 'Bob'; // <- 에러!
//2. const는 선언된 변수에 새로운 값을 정의할 수 없어요. 변수 값이 더이상 변경되지 않도록 할때 사용해요
const num3 = 30;
num3 = 'Bob'; // <- 에러!
let 은 선언은 1번만 가능하고 값은 변경할 수 있다.
const는 값을 변경할 수 없다.
Template Literal
const newText = `${hello}! ${introudce} 그리고 ${age}살이야`
Desturcturing(구조 분해 할당)
const grab = {
name : '그랩',
age : 27
};
const people = ['민수','철수']
var {name, age} = grab;
console.log(name); //그랩이 출력됩니다.
const [minsoo, chulsoo] = people;
map, forEach
//첫번째 파라미터에는 값, 두번째 파라미터에는 순서(index)가 들어간다.
products.forEach(function (product, index) {
console.log((index + 1) + '번째 호출');
console.log(product);
})
//동일하게 조회합니다.
products.map(function(product, index){
console.log((index + 1) + '번째 호출');
console.log(product);
});
//productNames는 각 product의 name이 들어간 배열이다
var productNames = products.map((product, index) => {
return product.name;
});
첫 번째 인자에는 배열에서 조회하는 값 , 두 번째 인자에는 순서(index)가 들어갑니다.
Lambda Function(람다 함수)
//람다식의 return 문을 생략할 수도 있습니다.
const getName = (name) => `${name} 입니다`
conditional ternary operator(3항 연산자)
const language = 'javascript';
if(language === 'javascript'){
console.log('재밌다')
}else{
console.log('재미없다')
}
if 조건문의 단축 형태
language === 'javascript' ? console.log('재밌다') : console.log('재미없다')
//아래와 같이 많이 활용됩니다.
const isJavascript = language === 'javascript'? true : false
//result에 true가 들어옵니다.
Ref : https://www.notion.so/ES6-4f47c2b3cf2e414cb592befa500571e8
s
'📱 Full-Stack' 카테고리의 다른 글
리액트 (0) | 2021.09.18 |
---|---|
웹 화면 구현하기 (0) | 2021.08.23 |
CSS (0) | 2021.08.18 |
html (0) | 2021.08.18 |