Skip to content

Commit d88ab2e

Browse files
committed
Add base chapter about numbers
1 parent 483bb56 commit d88ab2e

6 files changed

Lines changed: 118 additions & 1 deletion

File tree

SUMMARY.md

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,10 @@
11
# Summary
22

33
* [Variables](variables/README.md)
4-
* [Numbers](variables/numbers.md)
4+
* [Types](variables/types.md)
5+
* [Numbers](numbers/README.md)
6+
* [Creation](numbers/create.md)
7+
* [Basic Operators](numbers/operators.md)
58
* [Strings](strings/README.md)
69
* [Creation](strings/create.md)
710
* [Concatenation](strings/concat.md)

numbers/README.md

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,7 @@
1+
# Numbers
2+
3+
JavaScript has only one type of numbers, it does not define different types of numbers, like integers, short, long, floating-point etc. A number could be a **Float** (ex: 1.23) or an **Integer** (ex: 10).
4+
5+
There is nothing magical or strange going on with these. You define variables and set their values to any number type.
6+
7+
In this chapter, we'll learn how to create number and do some operations on them (like additions, subtractions, ...).

numbers/advanced.md

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,7 @@
1+
2+
* **Increment**: Given a = 5
3+
* ```c = a++```, Results: c = 5 and a = 6
4+
* ```c = ++a```, Results: c = 6 and a = 6
5+
* **Decrement**: Given a = 5
6+
* ```c = a--```, Results: c = 5 and a = 4
7+
* ```c = --a```, Results: c = 4 and a = 4

numbers/create.md

Lines changed: 42 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,42 @@
1+
# Creation
2+
3+
Create a number is easy, it's done just like any other variable type using the ```var``` keyword.
4+
5+
Numbers can be created from an absolute value:
6+
7+
```
8+
// This is a float:
9+
var a = 1.2;
10+
11+
// This is a integer:
12+
var b = 10;
13+
```
14+
15+
Or from the value of another variable:
16+
17+
```
18+
var a = 2;
19+
var b = a;
20+
```
21+
22+
23+
---
24+
25+
Create a variable `x` which equals `10` and create a variable `y` which equals `a`.
26+
27+
```js
28+
var a = 11;
29+
```
30+
31+
```js
32+
var a = 11;
33+
34+
var x = 10;
35+
var y = a;
36+
```
37+
38+
```js
39+
assert(x == 10 && y == a);
40+
```
41+
42+
---

numbers/operators.md

Lines changed: 39 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,39 @@
1+
# Operators
2+
3+
You can apply operations to numbers using some basic operators like:
4+
5+
* **Addition**: ```c = a + b```
6+
* **Subtraction**: ```c = a - b```
7+
* **Multiplication**: ```c = a * b```
8+
* **Division**: ```c = a / b```
9+
10+
You can use parentheses just like in math to separate calcul execution.
11+
12+
13+
---
14+
15+
Create a variable `x` which equals to the addition of `a` and `b` divided by `c`and finally multiplicated by `d`.
16+
17+
```js
18+
var a = 2034547;
19+
var b = 1.567;
20+
var c = 6758.768;
21+
var d = 45084;
22+
23+
var x =
24+
```
25+
26+
```js
27+
var a = 2034547;
28+
var b = 1.567;
29+
var c = 6758.768;
30+
var d = 45084;
31+
32+
var x = ((a + b) / c) * d;
33+
```
34+
35+
```js
36+
assert(x == (((a + b) / c) * d));
37+
```
38+
39+
---

variables/types.md

Lines changed: 19 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,19 @@
1+
# Variable types
2+
3+
Computers are sophisticated and can make use of more complex variables than just numbers. This is where variable types come in. Variables come in several types and different languages support different ones.
4+
5+
The most common ones are:
6+
7+
* **Numbers**
8+
* **Float**: a number, like 1.21323, 4, 100004 or 0.123
9+
* **Integer**: a natural number like 1, 12, 33, 140 but not 1.233
10+
11+
* **String**: a line of text like "boat", "elephant" or "damn, you are tall!"
12+
13+
* **Boolean**: either true or false, but nothing else
14+
15+
* **Arrays**: a collection of values like: 1,2,3,4,'I am bored now'
16+
17+
* **Objects**: a representation of a more complex object
18+
19+
JavaScript is a “loosely typed” language, which means that you don't have to explicitly declare what type of data the variables are. You just need to use the ```var``` keyword to indicate that you are declaring a variable, and the interpreter will work out what data type you are using from the context, and use of quotes.

0 commit comments

Comments
 (0)