w3schools로 자바스크립트 공부한 내용을 정리합니다.


자바스크립트는 데이터를 다른 형태들로 보여줄 수 있다.


HTML 요소를 출력 시 innerHTML

HTML output은 document.write( )

alert 박스는 window.alert( )

브라우저 콘솔창은 console.log( )


1
2
3
4
5
6
7
8
9
10
11
12
13
<!DOCTYPE html>
<html>
<body>
<h2>innerHTML</h2>
<p id="test"></p>
 
<script>
document.getElementById("test").innerHTML = 1 + 2;
</script>
 
</body>
</html> 
 
cs


1
2
3
4
5
6
7
8
9
10
11
12
13
<!DOCTYPE html>
<html>
<body>
 
<h2>document.write( )</h2>
 
<script>
document.write(2 + 3);
</script>
 
</body>
</html> 
 
cs


1
2
3
4
5
6
7
8
9
10
11
12
13
14
<!DOCTYPE html>
<html>
<body>
 
<h2>window.alert(</h2>);
 
<script>
window.alert(3 + 4);
alert(4 + 5);
</script>
 
</body>
</html> 
 
cs

window는 생략해도 된다. 


1
2
3
4
5
6
7
8
9
10
11
12
13
<!DOCTYPE html>
<html>
<body>
 
<h2>console.log( )</h2>
 
<script>
console.log(1 + 2);
</script>
 
</body>
</html> 
 
cs

디버깅 모드로 log를 확인할 수 있다.


+ Recent posts