TIL) Java Script - Boolean, Array, Object

oatraspberry·2022년 12월 11일
post-thumbnail

브라우저는 HTML을 열고, HTML은 CSS와 자바스크립트를 가져온다.
HTML이 접착제다

variable을 만들기 위한 방법
1. const 사용함. -> 값이 바뀔 수 없음, 기본적으로 사용함.
constant = 상수 = 바뀌지 않는 값
2. let 사용함. -> 값을 바꾸는 게 필요할 때 variable을 업데이트 하고 싶을 때 사용함.

기본적으로는 const를 사용하고, 필요할 때만 let 사용하되, var은 쓰지 말 것.

항상 const, 가끔 let, 사용X var.

const a = 10;
const b = 3;
let myName = "jinah";

console.log(a + b); // 13
console.log(a * b); // 30
console.log(a / b); // 3.3333333333333335
console.log("Hello " + myName); // Hello jinah

myName = "eunwoo";
console.log("your new name is " + myName); // your new name is eunwoo

Booleans

true, false, null, undefined
자바스크립트의 데이터 타입 중에는 '존재하지 않음' 또는 '정의되지 않음' 또는 'null=아무것도 없음'이 있다.

true

켜져있음

false

꺼져있음

null

비어있음

undefined

something이라는 variable을 만들고 있지만, 값을 주고 있지 않은 것.
variable은 존재하는데 정의되지 않은 것.
컴퓨터 메모리 안에는 존재함. 공간은 있지만 값이 들어가지 않은 것.

Arrays

array 안에서 항목을 받아올 수 있다.
array에 하나 더 추가할 수 있다.

규칙

  1. 시작과 끝에 대괄호 []를 사용해야 한다.
  2. array 안 각각의 항목은 쉼표로 분리되어 있어야 한다.
  3. 배열은 1부터가 아닌 0부터 센다.
const daysOfWeek = ["mon", "tue", "wed", "thu", "fri", "sat"];

// Get Item from Array
console.log(daysOfWeek);

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

console.log(daysOfWeek);

Objects

property를 가진 데이터를 저장하도록 해준다.

const player = { 
  name: "jinah",
  points: 50,
  handsome: true,
  fat: false,
};

console.log(player); // {name: 'jinah', points: 50, handsome: true, fat: false}
player.points = player.points + 15;
console.log(player.points); // 65
profile
개발자가 될테야

0개의 댓글