그 땐 Front했지/그 땐 JavaScript했지

[Nomad/바닐라 JS Challenges] 2일차 | Ch02 WELCOME TO JAVASCRIPT

루이란 2022. 6. 8. 20:06
728x90

참고자료: 노마드 코더 바닐라 JS로 크롬 앱 만들기 https://nomadcoders.co/javascript-for-beginners/lobby

1.  Basic Data Types


// Integer
1, 2, 3

// String, 따옴표로 감싼다.
"Hello"

 

2.  Variables


const a = 5;
const b = 2;
const myName = "yeram";

console.log(a + b);
console.log(a * b);
console.log(a / b);
console.log("Hello" + myName);

👉🏻변수를 선언해 게으른 개발자가 되어보자! 코드의 재사용성을 높인다.

👉🏻JS에서는 변수를 카멜표기법으로 쓴다.

 

3.  const and let


let a = 5;
let b = 2;
const myName = "yeram";

a = 6; // 가능
myName = "sehyeon" // 불가능

👉🏻변수를 선언할 때 constlet을 사용할 수 있다.

👉🏻const는 변수 값을 변경시킬 수 없다. let은 변수 값을 수정할 수 있다.

👉🏻옛날 표기인 var도 있지만 안 쓰는게 좋다.

 

4.  Booleans


const amIFat = false;
let something;

console.log(amIFat); // false
console.log(something); // undefined
console.log(yeram); // null

✍🏻nullfalseundefined의 차이점은? false는 false라는 값을 가진 것이고 null은 값이 존재하지 않는 것이다. 그리고 undefined는 변수가 선언되어서 메모리 공간은 있지만 값이 들어가지 않은 것이다.

 

5.  Arrays


const daysOfWeek = ["mon", "tue", "wed", "thu", "fri", "sat", "sun"];

// Get Item from Array
console.log(daysOfWeek[5]); // sat

// Add one more day to the Array
daysOfWeek.push("sun");

👉🏻리스트란 많은 변수들을 그룹화하는 것이다. 

👉🏻리스트는 대괄호 안에 정의하고 대괄호를 이용해 요소를 꺼낼 수 있다. push를 이용해 요소를 추가할 수 있다.

 

6.  Objects


const player = {
    name: "yeram",
    points: 10,
    fat: true,
};

console.log(player.name); // yeram
console.log(player["name"]); // yeram

player.lastName = "sehyeon";
player.points = 15;

👉🏻객체는 중괄호를 이용해 만든다. 하나의 주제를 기준으로 값이 저장된다.

👉🏻온점이나 대괄호를 이용해 값에 접근할 수 있다. 온점을 이용해 값을 추가하거나 변경할 수 있다.

728x90