mirror of
https://github.com/Nezumi-2711/javascript-training.git
synced 2026-09-22 13:38:43 +00:00
Init operators and comparisons sample
This commit is contained in:
@@ -0,0 +1,12 @@
|
||||
<!DOCTYPE html>
|
||||
<html lang="en">
|
||||
<head>
|
||||
<meta charset="UTF-8" />
|
||||
<meta name="viewport" content="width=device-width, initial-scale=1.0" />
|
||||
<title>Javascript Training</title>
|
||||
</head>
|
||||
<body>
|
||||
<h1>Javascript Training</h1>
|
||||
<script src="./index.js"></script>
|
||||
</body>
|
||||
</html>
|
||||
@@ -0,0 +1,40 @@
|
||||
// Basic Operators
|
||||
// Math operators
|
||||
const now = 2023;
|
||||
const ageNezumi = now - 2001;
|
||||
const ageSarah = now - 2006;
|
||||
console.log(ageNezumi, ageSarah);
|
||||
|
||||
console.log(ageNezumi * 2, ageNezumi / 10, 2 ** 3);
|
||||
// 2 ** 3 means 2 to the power of 3 = 2 * 2 * 2
|
||||
|
||||
const firstName = "Phan";
|
||||
const lastName = "Nezumi";
|
||||
console.log(firstName + " " + lastName);
|
||||
|
||||
// Assignment operators
|
||||
let a = 10 + 5; // 15
|
||||
a += 10; // a = a + 10 = 25
|
||||
a *= 4; // a = a * 4 = 100
|
||||
a++; // a = a + 1
|
||||
a--;
|
||||
a--;
|
||||
console.log(a);
|
||||
|
||||
// Comparison operators
|
||||
console.log(ageNezumi > ageSarah); // >, <, >=, <=
|
||||
console.log(ageSarah >= 18);
|
||||
|
||||
console.log(now - 1991 > now - 2018);
|
||||
|
||||
////////////////////////////////////
|
||||
// Operator Precedence
|
||||
|
||||
console.log(now - 2001 > now - 2006);
|
||||
|
||||
let t, u;
|
||||
t = u = 25 - 10 - 5; // x = y = 10, x = 10
|
||||
console.log(t, u);
|
||||
|
||||
const averageAge = (ageNezumi + ageSarah) / 2;
|
||||
console.log(ageNezumi, ageSarah, averageAge);
|
||||
Reference in New Issue
Block a user