본문 바로가기

Front-End

[JavaScript] JS vs HTML

JavaScript 는 동적이다.

→ html 위에서 작동하며, 사용자와 상호작용한다.

 

 

1. JavaScript를 html 코드에 넣기

<body>
    <h1>JavaScript 1</h1>
    <script>
      document.write("hello world");
    </script>
 </body>

 

<body>태그 안에 <script>태그를 넣어서 사용할 수 있다.

 

이러면 html에 hello world를 직접 출력하는 것과 다를 바가 없다고 생각할 수도 있다.

 

2. html과 다른점

<!DOCTYPE html>
<html>
  <head>
    <meta charset="utf-8" />
    <title></title>
  </head>
  <body>
    <h1>JavaScript</h1>
    <script>
      document.write(1 + 1);
    </script>
    <h1>HTML</h1>
    1+1
  </body>
</html>

 

html과 JavaScript의 차이점은

JavaScript는 동적이고, html은 정적이라는 것이다.