-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathProject5_comparisons_type_coercion.html
More file actions
55 lines (44 loc) · 1.47 KB
/
Copy pathProject5_comparisons_type_coercion.html
File metadata and controls
55 lines (44 loc) · 1.47 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8">
<title>Comparisons and Type Coercion</title>
<script src="JS/main.js"></script>
</head>
<body>
<h1>Project 5: comparisons_type_coercion</h1>
<p id="Not" onclick="not_Function()">Click here</p>
</body>
</html>
//main.js
// 1. Using typeof to display the data type of a variable
document.write(typeof "Hello World");
document.write("<br>");
// 2. Type Coercion: combining a string and a number
// This will result in "105" as JavaScript treats the 5 as text
document.write("10" + 5);
document.write("<br>");
// 3. Double Equal (==) Comparison
// Returns true because the values are the same
document.write(10 == 10);
document.write("<br>");
// 4. Triple Equal (===) Comparison
// Returns false because the data types are different (string vs number)
document.write("10" === 10);
document.write("<br>");
// 5. Greater Than (>) and Less Than (<) Operators
document.write(5 > 2); // true
document.write("<br>");
document.write(5 < 2); // false
document.write("<br>");
// 6. Logical AND (&&) Operator
// Returns true because both statements are true
document.write(10 > 5 && 11 > 6);
document.write("<br>");
// 7. Logical OR (||) Operator
// Returns true because at least one statement is true
document.write(5 > 10 || 10 > 4);
document.write("<br>");
// 8. Logical NOT (!) Operator
// Returns true because 5 is NOT greater than 10
document.write(!(5 > 10));