| 1 |
--- |
| 2 |
kernelspec: |
| 3 |
display_name: Javascript (Node.js) |
| 4 |
language: javascript |
| 5 |
name: javascript |
| 6 |
--- |
| 7 |
|
| 8 |
## A notebook that uses IJavascript kernel |
| 9 |
|
| 10 |
```{code-cell} |
| 11 |
let x = 5; |
| 12 |
const y = 6; |
| 13 |
var z = 10; |
| 14 |
``` |
| 15 |
|
| 16 |
```{code-cell} |
| 17 |
x + y; |
| 18 |
``` |
| 19 |
|
| 20 |
```{code-cell} |
| 21 |
function add(num1, num2) { |
| 22 |
return num1 + num2 |
| 23 |
} |
| 24 |
``` |
| 25 |
|
| 26 |
```{code-cell} |
| 27 |
add(x, y); |
| 28 |
``` |
| 29 |
|
| 30 |
```{code-cell} |
| 31 |
const arrowAdd = (num1, num2) => num1 + num2; |
| 32 |
``` |
| 33 |
|
| 34 |
```{code-cell} |
| 35 |
arrowAdd(x, y); |
| 36 |
``` |
| 37 |
|
| 38 |
```{code-cell} |
| 39 |
const myCar = { |
| 40 |
color: "blue", |
| 41 |
weight: 850, |
| 42 |
model: "fiat", |
| 43 |
start: () => "car started!", |
| 44 |
doors: [1,2,3,4] |
| 45 |
} |
| 46 |
``` |
| 47 |
|
| 48 |
```{code-cell} |
| 49 |
console.log("color:", myCar.color); |
| 50 |
``` |
| 51 |
|
| 52 |
```{code-cell} |
| 53 |
console.log("start:", myCar.start()); |
| 54 |
``` |
| 55 |
|
| 56 |
```{code-cell} |
| 57 |
for (let door of myCar.doors) { |
| 58 |
console.log("I'm door", door) |
| 59 |
} |
| 60 |
``` |
| 61 |
|
| 62 |
```{code-cell} |
| 63 |
myCar; |
| 64 |
``` |
| 65 |
|
| 66 |
```{code-cell} |
| 67 |
class User { |
| 68 |
constructor(name){ |
| 69 |
this.name = name; |
| 70 |
} |
| 71 |
sayHello(){ |
| 72 |
return "Hello, I'm " + this.name; |
| 73 |
} |
| 74 |
} |
| 75 |
``` |
| 76 |
|
| 77 |
```{code-cell} |
| 78 |
let John = new User("John"); |
| 79 |
John.sayHello(); |
| 80 |
``` |