Skip to content

Commit

Permalink
Remove extra space around code blocks
Browse files Browse the repository at this point in the history
  • Loading branch information
joemull committed Jan 2, 2023
1 parent 3429299 commit cf02754
Show file tree
Hide file tree
Showing 3 changed files with 0 additions and 66 deletions.
26 changes: 0 additions & 26 deletions javascript-evaluation-with-operators.md
Original file line number Diff line number Diff line change
Expand Up @@ -15,44 +15,34 @@ In doing so, operators demonstrate how data types are used in JavaScript, showin
## Combining and adding

Say you're programming a calculator. The user enters an equation.

```js
2 + 2
```

The output should be `4`.

On the other hand, let's say you're programming a messaging app. The user types 2, and then another 2.

```js
"2" + "2"
```

The output should be `22`.

The plus sign (`+`) is an *operator* that combines strings together or finds the sum of numbers, depending on the data types.

When the values are strings, the operation is *concatenation*:

```js
"My name is " + "Joe" + ". What is your name?"
'WC1E ' + '7HX'
```

When they are numbers, the operation is summation:

```js
1203910516 + 150151956
-294 + 24
23913 + 42 + 95
```

If you use `+` with a string and a number, JavaScript will first turn the number into a string and then combine them (concatenation):

```js
"She's turning " + 72
```

This evaluates to `She's turning 72`.

### Check your understanding
Expand All @@ -76,48 +66,36 @@ What's the evaluated value of each of these expressions?
## Comparing strings or numbers

To check if two things are the same, you can use the double equals sign operator (`==`):

```js
'orange' == 'purple'
```

The result of this operator is always a boolean value, `true` or `false`. In the above case, it's `false`.

JavaScript doesn't know what 'orange' and 'purple' mean, but it knows they are not spelled the same way, so it believes they are not the same.

Here's one more example that evaluates to `false`:

```js
'London' == 'the UK capital'
```

This one is `true`:

```js
'hope' == 'hope'
```

Here's one with numbers:

```js
1900 == 1899
```

To check that things are *not* the same, you can put an exclamation point in front of an equals sign (`!=`):

```js
'orange' != 'purple'
```

The above code evaluates to `true` because they are not the same word.

You can also use `<` and `>` to compare numeric values:

```js
1900 > 1899
1 > 4
```

### Check your understanding

Do these evaluate to `true` or `false`?
Expand All @@ -132,19 +110,15 @@ Do these evaluate to `true` or `false`?
## Arithmetic operators

JavaScript has operators for mathematics: `+`, `-`, `/`, `*`.

```js
1 + 5 - 2
100 / 5
2 * 6 / 3 + 1
```

Like in math, you can use parentheses to control the order of operations:

```js
2 * 6 / (3 + 1)
```

If you're not fond of math, don't worry--these are only used in simple ways in most web applications.

### Check your understanding
Expand Down
6 changes: 0 additions & 6 deletions javascript-setup.md
Original file line number Diff line number Diff line change
Expand Up @@ -22,11 +22,9 @@ You can do lots and lots of things with JavaScript, including altering HTML and
Like HTML and CSS, JavaScript is supported by all major web browsers, so all you need to run JavaScript code is a web browser.

For example, if you open up your inspector pane, navigate to the Console, type this in, and press Enter, the browser will say “Hello” back to you.

```js
console.log('Hello');
```

![Running JavaScript in the browser](images/javascript-run-in-browser.png)

You can also run JavaScript at the command line and through code editors like VS Code, which has a button for running the currently opened `.js` file.
Expand All @@ -52,15 +50,12 @@ It will take a few weeks to understand how this works, but you don't need to und
You already know how to write comments for other humans in HTML, using `<!-- -->`, and in CSS, using `/* */`.

In JavaScript, you can use a double slash (`//`) to comment everything to the right of it, for the rest of the line:

```js
console.log('This will run');
// console.log('This will not run');
console.log('This will run'); // But not this comment
```

You can also use the same syntax as CSS to make block comments:

```js
console.log('This will run');
/*
Expand All @@ -70,7 +65,6 @@ Neither will this line.
console.log('or this');
*/
```

## Rights
Copyright Birkbeck, University of London

Expand Down
34 changes: 0 additions & 34 deletions javascript-values-and-data-types.md
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,6 @@ As a sequence of letters, the word "hello" is declared to JavaScript as a partic
Strings are the first JavaScript data type to know about. A string can be nearly any sequence of letters, numbers, or unicode items.

These are all valid strings:

```js
'Hello'
"Hello"
Expand All @@ -35,7 +34,6 @@ These are all valid strings:
"d9fs0df9we0r235203n5235024923s9fsdf-sd9fw-9n23-r2n3f9-9SF-ZX9ZF2092N30FN20F9N"
"!P£$(&^)'£$(&^£!$P(!'FP(J!F)(£J!"
```

There are two basic rules for forming strings:

1. They must start and end with matching quotation marks, either single (`'`) or double (`"`). Without quotation marks, JavaScript will think the contents of the string are variable names, and we don't want that.
Expand All @@ -45,95 +43,73 @@ There are two basic rules for forming strings:
What does this mean? Two things, in practice:

- You can alternate the marks inside the string so that they are different from the start and end marks. For example, use double on the outside, and single on the inside, or vice versa:

```js
"How do you say 'hello' in Korean?"
'How do you say "hello" in Korean?'
```

- You can use the same mark, but put a backslash (`\`) in front of it, so that it eludes or *escapes* the algorithm that JavaScript uses to figure out which things are strings:
```js
"How do you say \"hello\" in Korean?"
'How do you say \'hello\' in Korean?'
```
What if you have a string that has a backslash in it? Escape it as well by putting another one in front of it:
```js
"The files are located at C:\\Users\\Documents"
```
JavaScript will interpret this as a valid string with a value of `The files are located at C:\Users\Documents`.
### Check your understanding
1. Can you make a string like this?
```js
'Hello"
```
2. How many valid strings does this line have? Where do they start and end?
```js
"There are many "ways" you can "interpret" things."
```
3. Is this a valid string?
```js
"I told him I'm \"excited\" 🙄"
```
## Number values
After strings, numbers are the next most common data type.
Numbers are declared in your code without any quotation marks, with `-` if they are negative, and with `.` as a decimal point for fractional numbers:
```js
3
8519
-62
8.52
.99
```
If you put quotation marks around numbers, JavaScript thinks they are strings:
```js
'8'
"105"
'-2'
```
### Check your understanding
1. Does JavaScript think this is a number?
```js
"8,325"
```
2. How about this?
```js
-39.2301
```
## Boolean values
Often you need a value that operates like a toggle switch, so that it can be turned on or off, say yes or no, or turn up true or false.
There is a special data type for these values, the *boolean* type.
These values are represented with keywords `true` and `false`:
```js
true
false
```
You don't put quotation marks around these words, or else they would be interpreted as strings.
### Check your understanding
Expand All @@ -152,37 +128,29 @@ In the absence of a working value, JavaScript will substitute the keyword `undef
This might happen if a string, boolean or number doesn't get set up the right way.
All of the following evaluate to `undefined`:
```js
True
orange
l0
```
You can also refer to and work with an empty value called `null`:
```js
null
```
This just lets you explicitly write that rather than a string, number, or boolean, you're declaring a blank, meaningless value.
At the moment, it might be unclear why this is useful, but you will see soon. For now, know it exists.
## The `typeof` operator
Like with `console.log();`, you can have JavaScript tell you the type of a value. Put `typeof` before the value, and JavaScript will evaluate its type.
```js
typeof 'blah blah'
```
By combining this with `console.log();`, you can check the type of anything:
```js
console.log(typeof 'blah blah');
```
![Logging typeof to the console](images/js-typeof-blah.png)
## But why?
Expand All @@ -200,5 +168,3 @@ Marijn Haverbeke, *Eloquent JavaScript: A Modern Introduction to Programming*, t
Copyright Birkbeck, University of London
<a rel="license" href="http://creativecommons.org/licenses/by/4.0/"><img alt="Creative Commons Licence" src="https://i.creativecommons.org/l/by/4.0/88x31.png" /></a><br />This work is licensed under a <a rel="license" href="http://creativecommons.org/licenses/by/4.0/">Creative Commons Attribution 4.0 International License</a>.

0 comments on commit cf02754

Please sign in to comment.