1function createMenu({ title, body, buttonText, cancellable }) {
2 // ...
3}
4
5createMenu({
6 title: "Foo",
7 body: "Bar",
8 buttonText: "Baz",
9 cancellable: true
10});
11
1function sum(...values) {
2 console.log(values);
3}
4sum(1);
5sum(1, 2);
6sum(1, 2, 3);
7sum(1, 2, 3, 4);
8
9
10function sum(...values) {
11 let sum = 0;
12 for (let i = 0; i < values.length; i++) {
13 sum += values[i];
14 }
15
16 return sum;
17}
18console.log(sum(1)); //1
19console.log(sum(1, 2)); //3
20console.log(sum(1, 2, 3)); // 5
21console.log(sum(1, 2, 3, 4)); //10
1const makeNoise = function() {
2 console.log("Pling!");
3};
4
5makeNoise();
6// → Pling!
7
8const power = function(base, exponent) {
9 let result = 1;
10 for (let count = 0; count < exponent; count++) {
11 result *= base;
12 }
13 return result;
14};
15
16console.log(power(2, 10));
17// → 1024
1
2function myFunction(x, y) {
3
4 if (y === undefined) {
5
6 y = 2;
7
8 }
9
10
11}
12
1<button class="btn btn-primary" onclick="transmit({search: document.getElementById('search_id').value});">
2 <span class="glyphicon glyphicon-search"></span>
3</button>