개발 언어/Javascript

Javascript #3 (alert, console)

Philip.Box 2019. 12. 11. 11:56

- JS file은 항상 body 아래에 있어야 함.

- sciprt는 <script/>이렇게 닫아줄 수 없음!

- <script ...> ... </script> 이렇게 닫아줘야 함.

1
2
3
4
5
6
7
8
9
10
11
12
<!DOCTYPE html>
<html>
  <head>
    <title>Hello Javascript</title>
    <meta charset="utf-8"/>
    <link rel="stylesheet" href="index.css"/>
  </head>
  <body>
    <h1>Hello World!</h1>
    <script src='index.js'></script>
  </body>
</html>
cs

 


Javascript - alert

index.js에 아래와 같이 입력

1
alert("Hello! This is Javascript!");
cs


- index.html을 실행시키면 아래와 같이 alert창이 실행되는 것을 확인할 수 있음.

- index.html에서 정상적으로 index.js를 읽었다는 것.


Javascript - console.log

index.js에 아래와 같이 입력

1
console.log("Hello! This is Javascript! - console")
cs


- 브라우저의 conole에서 확인하겠다는 것.
- index.html를 실행시킨 후, 개발자 도구(F12)를 눌러서 확인.