가장 기본적인 타입
// 따로 선언하지 않더라도 연산가능
정수(integer) : 5 , 10 , 15, 20
소수(float) : 1.1 , 12.34
// 텍스트는 그냥 적으면 컴퓨터가 못알아먹음 , " " 안에 선언해야함
문자(String) : "KIM" , "PARK"
ex) "KIM " + "PARK" -> KIM PARK
//변수선언
const a = 5; // 변하지 않음
let a = 10; // 변동 가능
var를 사용해도 문제는 없지만 문제가 생겨도 말해주지않음, 값 보호가 안됨
//boolean
const a = true; //참
const b = false; //거짓
const c = null; // 없는상태
let d; // undefined , 컴퓨터 메모리는 차지 하지만 값이 없음
//arrays
const a = [1,2,"kang","text"]; //배열만들기
a.push("haha"); //배열 값 추가 1,2,"kang","text","haha"
a.pop(index값); // 해당 자리 값 삭제
//OBJECT
-> object는 property를 가진 데이터를 저장해주며, { } 를 사용한다.
설명이 필요하지 않은 데이터 리스트들은 array로,
설명이 필요한 정보가 담긴 데이터 리스트들은 object로!
const player = {
name:"kim",
points:10,
location:"busan",
};
console.log(player.location);
//Object 안의 프로퍼티 값 변경은 가능 , const에 구애받지 않음
player.location="seoul";
console.log(player.location);
//property 추가
player.sex = "man";
console.log(player);
//Object자체를 변경할 시에는 오류가 뜸
player = false;
//Function -> 계속 반복해서 사용 할 수 있는 코드조각
function sayHello(){
console.log("HI")
};
sayHello();
function plus(a,b){
console.log(a+b);
}
plus(5,6);
const Player={
name : "Kim",
letter : function(a){
console.log("letter info: " + a);
}
}
Player.letter("Fighting");
//return
함수를 실행했을때 반환받는 값
const Calculator = {
plus : function(a,b){
return a+b;
},
minus : function(a,b){
return a-b;
},
gop : function(a,b){
return a*b;
}
}
const plus = Calculator.plus(5,6);
console.log(plus);
//타입확인
typeof variable
//타입변경
parseInt() -> String을 number로 변환