JavaScript 기초 1

송범·2024년 11월 19일

자바스크립트 기본 문법

  • 자바스크립트는 컴파일을 하지 않는다. -> 즉 런타임 시에 타입이 결정된다!!
    선언만 하면 undefined 상태이다.
  • var 쓰지말기 const나 let을 사용해야 한다.
let name = "이순신" //변경 가능하다
name = "김정수"
console.log(name);

const name1 = "이순신";
//name1 = "김정수";  const는 상수라 변경 불가하다.
console.log(name);


for(let i = 0; i<9;i++){
    console.log(i); //0~8
}



function checkType(value){ //기본 방식
    return typeof value; //typeof를 사용하여 타입체크 가능!
}

checkType => (value2) => { //arrow function 방식 => 자바는 람다 , 리액트에서 많이 쓴다. 
	return typeof value2
}


console.log(checkType(5)); //number

console.log(checkType("문자")); //string

console.log(checkType({})); // object로 취급이 된다.


console.log(checkType(null)); //null -> object 취급이 된다.

const fruits = ['🥝','🥥','🍌']
console.log(typeof fruits); //object 타입이다.


console.log(checkType(function(){})); //function 타입이다.

window.addEventListener(
    "hashchange",
    () => {
    
    console.log(location.hash.substring(1));
    },
    false,
);

  • 자바스크립트에서의 얕은복사 kiwi와 tomato는 같은 주소번지를 바라보고 있다.


let kiwi = {
    name:"kiwi",
    display : "🥝"
}
//객체 타입은 참조값이 복사되어 전달된다.

let tomato = kiwi //같은 주소번지 x001을 가르키고 있다.

console.log(kiwi);


console.log(tomato);

tomato.display= "🍅"
kiwi.name = "tomato"


console.log(tomato);
console.log(kiwi);

console.log(tomato['display']); //배열처럼 key값을 줘도 결과 출력이 된다.
profile
BackEnd&Data Scientist가 되고 싶은 개발 기록 노트

0개의 댓글