-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathVariables.txt
134 lines (97 loc) · 3.48 KB
/
Variables.txt
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
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
Variables
Var
In this lesson, we will cover how to use the var, let, and const keywords to create variables.
var myName = 'Arya';
console.log(myName);
// Output: Arya
Let’s consider the example above:
var, short for variable, is a JavaScript keyword that creates, or declares, a new variable.
myName is the variable’s name. Capitalizing in this way is a standard convention in JavaScript called camel casing. In camel casing you group words into one, the first word is lowercase, then every word that follows will have its first letter uppercased. (e.g. camelCaseEverything).
= is the assignment operator. It assigns the value ('Arya') to the variable (myName).
'Arya' is the value assigned (=) to the variable myName. You can also say that the myName variable is initialized with a value of 'Arya'.
After the variable is declared, the string value 'Arya' is printed to the console by referencing the variable name: console.log(myName).
Variable let
let meal = 'Enchiladas';
console.log(meal); // Output: Enchiladas
meal = 'Burrito';
console.log(meal); // Output: Burrito
-------------------------------------------
let price;
console.log(price); // Output: undefined
price = 350;
console.log(price); // Output: 350
--------------------------------------------
let changeMe = true;
changeMe = false;
console.log(changeMe); //print false
variable const
const myName = 'Gilberto';
console.log(myName); // Output: Gilberto
variables
Mathematical Assignment Operators
let w = 4;
w = w + 1;
console.log(w); // Output: 5
-----------------------------------------
let w = 4;
w += 1;
console.log(w); // Output: 4
---------------------------------------------
let x = 20;
x -= 5; // Can be written as x = x - 5
console.log(x); // Output: 15
let y = 50;
y *= 2; // Can be written as y = y * 2
console.log(y); // Output: 100
let z = 8;
z /= 2; // Can be written as z = z / 2
console.log(z); // Output: 4
----------------------------------------------
let levelUp = 10;
let powerLevel = 9001;
let multiplyMe = 32;
let quarterMe = 1152;
// Use the mathematical assignments in the space below:
levelUp += 5;
powerLevel -= 100;
multiplyMe *= 11
quarterMe /= 4
// These console.log() statements below will help you check the values of the variables.
// You do not need to edit these statements.
console.log('The value of levelUp:', levelUp);
console.log('The value of powerLevel:', powerLevel);
console.log('The value of multiplyMe:', multiplyMe);
console.log('The value of quarterMe:', quarterMe);
Variables
The Increment and Decrement Operator
let a = 10;
a++;
console.log(a); // Output: 11
-----------------------------------
let b = 20;
b--;
console.log(b); // Output: 19
String Concatenation with Variables
let myPet = 'armadillo';
console.log('I own a pet ' + myPet + '.');
// Output: 'I own a pet armadillo.'
String Interpolation
const myPet = 'armadillo';
console.log(`I own a pet ${myPet}.`);
// Output: I own a pet armadillo.
----------------------------------
const myName = 'Joao';
const myCity = 'Famalicao';
console.log(`My name is ${myName}. My favorite city is ${myCity}.`)
typeof operator
const unknown1 = 'foo';
console.log(typeof unknown1); // Output: string
const unknown2 = 10;
console.log(typeof unknown2); // Output: number
const unknown3 = true;
console.log(typeof unknown3); // Output: boolean
-----------------------------------------------------------
let newVariable = 'Playing around with typeof.';
console.log(typeof newVariable);
newVariable = 1
console.log(typeof newVariable)