Loading...

JavaScript / / 2022. 3. 11. 16:23

자바스크립트 1강. 자료형

반응형

자바스크립트 해석기는 브라우저이다.

따로 설치해줄 프로그램은 없다.

 

파일을 생성할 때 확장자를 .js로 만들지 않고

.html로 만들어준다.

 

브라우저는 .js파일을 읽지 못하기 때문이다.

html 파일안에 있는 자바스크립트 언어를 해석하는 것이다.

 

그래서 자바스크립트가 스크립트 언어인 것이다.

스크립트 언어는 기생언어이다!!

 

html 파일 안에서 <script></script> 태그 안에 자바 스크립트 코드를 적어준다.

이 태그 안에 있는 코드는 브라우저가 해석하는 것이 아니다.

 

브라우저 엔진은 html을 분석해서 그림을 그려주고

자바스크립트 코드를 해석하는 인터프리터가 브라우저 안에 따로있다.

 

인터프리터는 실행시에 한줄씩 해석하고 실행된다.

 


 

자바스크립트의 자료형은 let 하나밖에 없다.

 

자료형이 따로 없기 때문에 모든 변수는 4바이트 공간을 갖고

Call by reference이다.

 

타입이 실행시에 결정되기 때문에 미리 사이즈를 잡아둘 수 없는것이다.

 

자바스크립트의 오브젝트타입은 JSON과 비슷하게 생겼다.

JSON(JavaScript Object Notation) 자바 스크립트 오브젝트 표기법인 이유이다.

다만 한가지 다른점은 자바스크립트 오브젝트는 키에 쌍따옴표가 붙지않는다.

 

<!DOCTYPE html>
<html lang="en">
<head>
    <meta charset="UTF-8">
    <meta http-equiv="X-UA-Compatible" content="IE=edge">
    <meta name="viewport" content="width=device-width, initial-scale=1.0">
    <title>Document</title>
</head>
<body>
    <h1>자바스크립트 공부하기 - 1단계(문법)</h1>
    <hr/>
    <script>
        // 1. 자료형
        // 값이 들어갈 때(실행 시) 타입 결정 => 인터프리터 언어
        let n1 = 10;
        console.log(n1);
        
        let n2 = 10.1;
        console.log(n2);
        
        let n3 = "문자열";
        console.log(n3);
        
        let n4 = '문자열';
        console.log(n4);
        
        let n5 = true;
        console.log(n5);
        
        let n6 = [1, 2, 3, 4, "가"]; // 타입이 일치하지 않아도 괜찮음
        console.log(n6);
        console.log(n6[3]);
        
        let n7 = { // 오브젝트 타입
            username:"ssar",
            password:"1234",
            age:25
        }
        console.log(n7);
        console.log(n7.username);
        
        let n8 = new Map();
        n8.set("username", "ssar");
        n8.set("password", "1234");
        console.log(n8);
        console.log(n8.get("username"));

    </script>
    <h2>안녕</h2>
</body>
</html>

 

이전에 html 파일을 실행할 때와 마찬가지로

Open with Live Server로 실행시켜준다.

 

 

만약 Open with Live Server 메뉴가 없다면

아래 플러그인을 설치해주자.

 

 

콘솔은 브라우저의 콘솔을 말한다.

F12 -> console창에서 확인이 가능하다.

 

 

 

 

[출처]

 

https://cafe.naver.com/metacoding

 

메타코딩 : 네이버 카페

코린이들의 궁금증

cafe.naver.com

메타 코딩 유튜브

https://www.youtube.com/c/%EB%A9%94%ED%83%80%EC%BD%94%EB%94%A9

 

메타코딩

문의사항 : getinthere@naver.com 인스타그램 : https://www.instagram.com/meta4pm 깃헙 : https://github.com/codingspecialist 유료강좌 : https://www.easyupclass.com

www.youtube.com

 

 

반응형