728x90
사칙연산
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8">
<meta name="viewport" content="width=device-width, initial-scale=1.0">
<title>Document</title>
<script>
//사칙연산
let result = 0;
result = 10 + 20;
document.write(result + "<br>");
result = 10 - 20;
document.write(result + "<br>");
result = 10 * 20;
document.write(result + "<br>");
result = 10 / 20;
document.write(result + "<br>");
result = 10 % 3;
document.write(result + "<br>");
</script>
</head>
<body>
</body>
</html>
증감연산
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8">
<meta name="viewport" content="width=device-width, initial-scale=1.0">
<title>Document</title>
<script>
//증감연산
let val = 10;
document.write(++val + "<br>"); //전위증감
document.write(val++ + "<br>"); //후위증감
document.write(val + "<br>");
</script>
</head>
<body>
</body>
</html>
비교연산
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8">
<meta name="viewport" content="width=device-width, initial-scale=1.0">
<title>Document</title>
<script>
//비교연산
let val1 = 20;
document.write((val > val1) + "<br>"); //false
//비교연산
let isResult = 10 == 10;
document.write(isResult + "<br>"); //true
isResult = 10 == '10';
document.write(isResult + "<br>"); //true (자동형변환 후 값을 비교해서)
isResult = 10 === '10';
document.write(isResult + "<br>"); //false (자료형이 일치하는지도 비교함)
//비교연산(C언의의 영향) => 안정성이 떨어짐
isResult = false == '0';
document.write(isResult + "<br>"); //true (false를 0과 같은 개념으로 봐서)
isResult = false == 0;
document.write(isResult + "<br>"); //true
isResult = "" == [];
document.write(isResult + "<br>"); //true
isResult = 0 == [];
document.write(isResult + "<br>"); //true
</script>
</head>
<body>
</body>
</html>
논리연산
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8">
<meta name="viewport" content="width=device-width, initial-scale=1.0">
<title>Document</title>
<script>
//논리연산
document.write((true && true) + "<br>"); //true
document.write((false && true) + "<br>"); //false
document.write((true || false) + "<br>"); //true
document.write(!false + "<br>"); //true
</script>
</head>
<body>
</body>
</html>
'Language > JavaScript + TypeScript' 카테고리의 다른 글
[JavaScript] 객체 (0) | 2024.03.12 |
---|---|
[JavaScript] 함수 실행 우선순위 (0) | 2024.03.12 |
[JavaScript] 콜백 함수 (0) | 2024.03.09 |
[JavaScript] 데이터 타입 (0) | 2024.03.07 |
JavaScript란? (1) | 2024.03.07 |