You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
Copy file name to clipboardExpand all lines: curriculum/challenges/english/25-front-end-development/review-javascript-variables-and-data-types/6723be264695fb7e619fe1fa.md
+22-22Lines changed: 22 additions & 22 deletions
Display the source diff
Display the rich diff
Original file line number
Diff line number
Diff line change
@@ -21,16 +21,16 @@ Data types help the program understand the kind of data it's working with, wheth
21
21
-**Floating point**: A floating point number is a number with a decimal point. Examples include 3.14, 0.5, and 0.0001.
22
22
-**String**: A string is a sequence of characters, or text, enclosed in quotes. `"I like coding"` and `'JavaScript is fun'` are examples of strings.
23
23
-**Boolean**: A boolean represents one of two possible values: `true` or `false`. You can use a boolean to represent a condition, such as `isLoggedin = true`.
24
-
-**Undefined and Null**: An undefined value is a variable that has been declared but not assigned a value. A null value is an empty value, or a variable that has intentionally been assigned a value of `null`.
24
+
-**Undefined and Null**: An `undefined` value is a variable that has been declared but not assigned a value. A `null` value is an empty value, or a variable that has intentionally been assigned a value of `null`.
25
25
-**Object**: An object is a collection of key-value pairs. The key is the property name, and the value is the property value.
26
26
27
27
Here, the `pet` object has three properties or keys: `name`, `age`, and `type`. The values are `Fluffy`, `3`, and `dog`, respectively.
28
28
29
29
```js
30
30
let pet = {
31
-
name:'Fluffy',
31
+
name:"Fluffy",
32
32
age:3,
33
-
type:'dog'
33
+
type:"dog"
34
34
};
35
35
```
36
36
@@ -39,8 +39,8 @@ let pet = {
39
39
In this example below, two symbols are created with the same description, but they are not equal.
- To assign a value to a variable, you can use the assignment operator `=`.
64
64
65
65
```js
66
-
cityName ='New York';
66
+
cityName ="New York";
67
67
```
68
68
69
69
- Variables declared using `let` can be reassigned a new value.
70
70
71
71
```js
72
-
cityName ='Los Angeles';
72
+
cityName ="Los Angeles";
73
73
console.log(cityName); // Los Angeles
74
74
```
75
75
76
76
- Apart from `let`, you can also use `const` to declare a variable. However, a `const` variable cannot be reassigned a new value.
77
77
78
78
```js
79
-
constcityName='New York';
80
-
cityName ='Los Angeles'; // TypeError: Assignment to constant variable.
79
+
constcityName="New York";
80
+
cityName ="Los Angeles"; // TypeError: Assignment to constant variable.
81
81
```
82
82
83
83
- Variables declared using `const` find uses in declaring constants, that are not allowed to change throughout the code, such as `PI` or `MAX_SIZE`.
@@ -103,35 +103,35 @@ let alsoCorrect = "This is also a string";
103
103
- Strings are immutable in JavaScript. This means that once a string is created, you cannot change the characters in the string. However, you can still reassign strings to a new value.
104
104
105
105
```js
106
-
let firstName ='John';
107
-
firstName ='Jane'; // Reassigning the string to a new value
106
+
let firstName ="John";
107
+
firstName ="Jane"; // Reassigning the string to a new value
108
108
```
109
109
110
110
## String Concatenation in JavaScript
111
111
112
112
- Concatenation is the process of joining multiple strings or combining strings with variables that hold text. The `+` operator is one of the simplest and most frequently used methods to concatenate strings.
113
113
114
114
```js
115
-
let studentName ='Asad';
115
+
let studentName ="Asad";
116
116
let studentAge =25;
117
-
let studentInfo = studentName +' is '+ studentAge +' years old.';
117
+
let studentInfo = studentName +" is "+ studentAge +" years old.";
118
118
console.log(studentInfo); // Asad is 25 years old.
119
119
```
120
120
121
121
- If you need to add or append to an existing string, then you can use the `+=` operator. This is helpful when you want to build upon a string by adding more text to it over time.
122
122
123
123
```js
124
-
let message ='Welcome to programming, ';
125
-
message +='Asad!';
124
+
let message ="Welcome to programming, ";
125
+
message +="Asad!";
126
126
console.log(message); // Welcome to programming, Asad!
127
127
```
128
128
129
-
- Another way you can concatenate strings is to use the concat method. This method joins two or more strings together.
129
+
- Another way you can concatenate strings is to use the `concat()` method. This method joins two or more strings together.
130
130
131
131
```js
132
-
let firstName ='John';
133
-
let lastName ='Doe';
134
-
let fullName =firstName.concat('', lastName);
132
+
let firstName ="John";
133
+
let lastName ="Doe";
134
+
let fullName =firstName.concat("", lastName);
135
135
console.log(fullName); // John Doe
136
136
```
137
137
@@ -140,7 +140,7 @@ console.log(fullName); // John Doe
140
140
- The `console.log()` method is used to log messages to the console. It's a helpful tool for debugging and testing your code.
141
141
142
142
```js
143
-
console.log('Hello, World!');
143
+
console.log("Hello, World!");
144
144
// Output: Hello, World!
145
145
```
146
146
@@ -149,7 +149,7 @@ console.log('Hello, World!');
149
149
- Semicolons are primarily used to mark the end of a statement. This helps the JavaScript engine understand the separation of individual instructions, which is crucial for correct execution.
150
150
151
151
```js
152
-
let message ='Hello, World!'; // first statement ends here
152
+
let message ="Hello, World!"; // first statement ends here
153
153
let number =42; // second statement starts here
154
154
```
155
155
@@ -201,7 +201,7 @@ let isLoggedin = true;
201
201
console.log(typeof isLoggedin); // boolean
202
202
```
203
203
204
-
- However, there's a well-known quirk in JavaScript when it comes to null. The `typeof` operator returns `object` for null values.
204
+
- However, there's a well-known quirk in JavaScript when it comes to `null`. The `typeof` operator returns `object` for `null` values.
0 commit comments