GV

GeezerVison

The World Wide Web, restored to 800 pixels of glory.

Home|About|Gaming cabinet|Archives|How it works|Starter sites

On this site

  • Sign in
  • ActionsCI/CD and automation
  • CodespacesCloud development environments
  • All Features
  • Documentation
  • Training
  • Certifications
  • Build with Copilot
  • Customize Copilot
  • Integrations
  • Trending repos
  • GitHub Sponsors
  • Developer articles
  • Enterprises

This view

  • Original page
  • New address

GeezerVison is showing github.com — Add article about else · op2146/javascript@d65d375

File tree

Expand file treeCollapse file tree
Open diff view settings
Filter options
  • conditional
    • else.md
    • if.md
Expand file treeCollapse file tree
Open diff view settings
Collapse file

‎conditional/else.md‎

Copy file name to clipboard
+56Lines changed: 56 additions & 0 deletions
  • Display the source diff
  • Display the rich diff
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,56 @@
1+
# Else
2+
3+
There is also an `else` clause that will be applied every time the first condition isn’t true. This is very powerful if you want to react to any value, but single out one in particular for special treatment:
4+
5+
```javascript
6+
var umbrellaMandatory;
7+
8+
if(country === 'England'){
9+
umbrellaMandatory = true;
10+
} else {
11+
umbrellaMandatory = false;
12+
}
13+
```
14+
15+
The `else` clause can be join with another `if`, lets remake the example from the previous article:
16+
17+
```javascript
18+
if(country === 'England') {
19+
...
20+
} else if(country === 'France') {
21+
...
22+
} else if(country === 'Germany') {
23+
...
24+
}
25+
```
26+
27+
28+
---
29+
30+
Fill up the value of `name` to validate the `else` condition.
31+
32+
```js
33+
var name =
34+
35+
if (name == "John") {
36+
37+
} else if (name == "Aaron") {
38+
// Valid this condition
39+
}
40+
```
41+
42+
```js
43+
var name = "Aaron";
44+
45+
if (name == "John") {
46+
47+
} else if (name == "Aaron") {
48+
// Valid this condition
49+
}
50+
```
51+
52+
```js
53+
assert(name == "Aaron");
54+
```
55+
56+
---
Collapse file

‎conditional/if.md‎

Copy file name to clipboardExpand all lines: conditional/if.md
+3-3Lines changed: 3 additions & 3 deletions
  • Display the source diff
  • Display the rich diff
Original file line numberDiff line numberDiff line change
@@ -8,19 +8,19 @@ var weather;
88
var food;
99
var currency;
1010

11-
if(country === 'England'){
11+
if(country === 'England') {
1212
weather = 'horrible';
1313
food = 'filling';
1414
currency = 'pound sterling';
1515
}
1616

17-
if(country === 'France'){
17+
if(country === 'France') {
1818
weather = 'nice';
1919
food = 'stunning, but hardly ever vegetarian';
2020
currency = 'funny, small and colourful';
2121
}
2222

23-
if(country === 'Germany'){
23+
if(country === 'Germany') {
2424
weather = 'average';
2525
food = 'wurst thing ever';
2626
currency = 'funny, small and colourful';

0 commit comments

Comments
0 (0)
You are visitor 01402792 — GeezerVison does not store the pages you look up.
Best viewed with Netscape Navigator 4.7 or Internet Explorer 6 at 800×600. No cookies required.