2 posts

·Tech·Frontend

[JavaScript] My Quick Reference for Core Basics

Full page →
Frontend

1. Setting location in HTML file and how to check document

When creating a file in HTML without creating a separate file, JavaScript can be processed within the embedded tag like CSS. Likewise, if you create a separate file, you can connect it through a link. 

Use

window.onload=function(){} to check what will be executed and displayed when the web browser is opened. The framework of the web is composed of HTML within tags, and additional tags can be inserted in JavaScript using .html(), etc.

+

While writing, it is necessary to check whether the desired result is obtained, so check by opening console.log() or alert().

When an error occurs, you can check the bug in the developer tool source by looking at F12 on the executed web page.

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
<!DOCTYPE html>
<html>
<head>
<meta charset@@T130 @@="UTF-8">
<title>Title@@T145@ @</title>
<style type="text/css"@ @T164@@></style>
<script type="text/javascript">
   window.onload = function() {
        console.log("Hello,world!"); 
        alert("Hello,world!");
   } 
</script>
</head>
 
<body>
</body>
cs

 


 

2. 타입의 설정, typeof()

 

변수의 타입을 설정할 때, java 에서는 타입별 표기가 다르고 배열은 int[] 이렇게 표기했지만, 자바스크립트에서는 모두 var 변수명 으로 작성이 가능하다. (배열포함)

변수를 변경할 수 없는 상수와 같은 개념이 있는데 let 변수명 으로 작성가능하다. 동일 변수명 설정불가!

 

그리고 변수 타입확인은 typeof() 로 가능하며, 결과값은 Number, String, Undefined, NaN, Function 등으로 나타난다.

 


 

3. 함수 선언하는 세 가지 방법

 

1 time →