Skip to content

Commit bfad714

Browse files
authored
Update working-with-classes-and-objects.mdx
1 parent fb59aa8 commit bfad714

File tree

1 file changed

+12
-6
lines changed

1 file changed

+12
-6
lines changed

docs/technologies/javascript/working-with-classes-and-objects.mdx

Lines changed: 12 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -12,19 +12,23 @@ As you begin your journey into the world of JavaScript and programming, you'll r
1212
![JavaScript Ninja](https://media.giphy.com/media/v1.Y2lkPTc5MGI3NjExNGUxN2MwYmYzYTRmNWY0YmNhNzFkOWIzYTY5YWM1ZDg4ZDY0ZDY2NyZlcD12MV9pbnRlcm5hbF9naWZzX2dpZklkJmN0PWc/jzHFPlw89eTqU/giphy.gif)
1313

1414
## What is a variable?
15-
A variable is simply an identifier or container that holds a value. It can contain data of different types, such as boolean, string, number, object, and array.
15+
A variable is simply an identifier or container that holds a value. It can contain data of different types, such as boolean, string, number, object, and array.
16+
1617
> 💡 A boolean variable holds either True or False, a string variable contains a sequence of characters enclosed in quotation marks, and an array is a collection of values of any data type.
1718
1819
![how variable works](https://user-images.githubusercontent.com/67129211/235643175-92e8441b-1360-4f55-9264-a225ab1165b9.png)
1920

2021
From the image above, the cup represents an empty variable; the milk and coffee are data of different data types. When you put the data into the cup, the cup becomes a variable of data type, coffee or milk.
2122

2223
## How to create variables in JavaScript
23-
To declare (create) variables in JavaScript, you need to use some built-in keywords such as var, let, and const. Let's talk briefly about them.
24+
To declare (create) variables in JavaScript, you need to use some built-in keywords such as var, let, and const. Let's talk briefly about them.
25+
2426
### The var keyword
25-
The var keyword is the oldest way of declaring variables in JavaScript, and it's not advisable to use it in your JavaScript programs because it is not block scope.
27+
The var keyword is the oldest way of declaring variables in JavaScript, and it's not advisable to use it in your JavaScript programs because it is not block scope.
28+
2629
> A variable is block-scoped when it only exists within the curly braces where it was declared and cannot be accessed outside the curly braces.
27-
Let’s take a look at some examples.
30+
Let’s take a look at some examples.
31+
2832
```js
2933
var ageInWords = "Eighteen"; //ageInWords holds the string value
3034
var male = true; //male holds a boolean value
@@ -44,15 +48,17 @@ let age = 20; //sets a variable to 20
4448
age = 5; // re-assign age to 5
4549
console.log(age); // prints 5 to the console
4650
```
47-
The code snippet above shows a variable created using the `let` keyword with an initial value of 20, then changed to 5.
51+
The code snippet above shows a variable created using the `let` keyword with an initial value of 20, then changed to 5.
52+
4853
### The const keyword
4954
The const keyword is used to declare variables that cannot be re-assigned to another value. It holds constant values.
5055
```js
5156
const age = 20;
5257
age = 10;
5358
console.log(age) //returns a TypeError: Assignment to constant variable. (Invalid)
5459
```
55-
> 💡 Don’t use the `var` keyword. Use `const` when you need to declare a constant and `let` when the variable can be re-assigned to another value.
60+
> 💡 Don’t use the `var` keyword. Use `const` when you need to declare a constant and `let` when the variable can be re-assigned to another value.
61+
5662
### Naming variables in JavaScript
5763
When naming variables in JavaScript, there are a few things you need to consider.
5864
- Variables can only start with a letter, underscore, or dollar sign. Numbers and other symbols can come after the first position.

0 commit comments

Comments
 (0)