-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathscript.js
More file actions
85 lines (67 loc) · 2.77 KB
/
script.js
File metadata and controls
85 lines (67 loc) · 2.77 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
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
// alert from external JavaScript file
// alert('I am an external JavaScript');
// splitting code into two alerts
// alert('Hello');
// alert('World');
// storing values in variables
let greeting = 'Hello, World!'; // greeting is the variable while 'Hello, World!' is the string value stored in it
// alert(greeting); // displays the value stored in the variable greeting
// let user = 'John',
// age = 25, this is another way of declaring multiple variables
// message = 'Hello';
// let user = 'John', age = 25, message = 'Hello'; // or you can write it in a single line
// When the stored string value is changed, the old data is forgotten from the variable even though it's still present in the code.
// declare two variables and copy data from one into the other.
// let hello = 'Hello world!';
// let message;
// message = hello;
// alert(hello); // Hello world!
// alert(message); // Hello world!
// note: no "use strict" in this example
num = 5; // the variable "num" is created if it didn't exist
// alert(num); // 5
// When the name contains multiple words, camelCase is used.
// That is: each word except first starting with a capital letter: myVeryLongName.
// const pageLoadTime has a different value each time the webpage reloads but it's constant after the page is loaded.
// let admin, name;
// name = "John";
// admin = name;
// alert(admin);
// Create a variable with the name of our planet. How would you name such a variable?
// Create a variable to store the name of a current visitor to a website. How would you name that variable?
let thirdPlanet = 'earth';
let currentVisitor= 'John';
// alert(`Hello, ${currentVisitor}! Welcome to ${thirdPlanet}.`);
// Backticks
// alert(`There were ${1 + 2} of them`)
// console.log(`There were ${1 + 2} of them`)
// Boolean
// let isBigger = 4 > 1;
// let isSmaller = 4 < 1;
// alert(isBigger); // true
// alert(isSmaller); // false
// console.log(isBigger); // true
// console.log(isSmaller); // false
// Null (nothing)
// let age = null;
// console.log(age);
// alert(age); // null
// Undefined means "value is not assigned"
// let age1;
// console.log(age1);
// alert(age1); // undefined
// Typeof
console.log(typeof '1234'); // "string"
console.log(typeof 1234); // "number"
console.log(typeof Math); // "object"
console.log(typeof alert); // "function"
console.log(typeof true); // "boolean"
console.log(typeof undefined); // "undefined"
console.log(typeof null); // "object" (this is a historical bug in JavaScript)
// prompt
// prompt('Name:', 'Enter your name here');
// let userEmail = prompt('Enter your email:','email@example.com');
// alert(`Your email "${userEmail}" has been accepted.`);
// confirm
// let isAdult = confirm('Are you 18 years old or older?');
// alert(isAdult); // true if OK is pressed