Published
Edited
Nov 22, 2021
1 fork
1 star
Insert cell
Insert cell
Insert cell
Insert cell
Insert cell
Insert cell
function testNum(a) {
let result;
if (a > 0) {
result = 'число положительное';
} else if (a == 0) {
result = "число равно нулю";
} else {
result = 'число не положительное';
}
return result;
}
Insert cell
testNum(-5)
Insert cell
Insert cell
Insert cell
result_for = {
let str = '';
for (let i = 0; i < 9; i++) {
str = str + i;
}
return str;
}
Insert cell
Insert cell
Insert cell
result_in = {
const object = {
a: 1,
b: 2,
c: 3
};

for (const property in object) {
return(`${property}: ${object[property]}`);
}
// "a: 1"
// "b: 2"
// "c: 3"
}
Insert cell
Insert cell
Insert cell
Insert cell
result_of_array = {
const array = [10, 20, 30];

for (let element of array) {
element += 1;
return(element);
}
// 11
// 21
// 31
}
Insert cell
Insert cell
result_of_map = {
const map = new Map([['a', 1], ['b', 2], ['c', 3]]);

for (const entry of map) {
return(entry);
}
// ['a', 1]
// ['b', 2]
// ['c', 3]

for (const [key, value] of map) {
return(value);
}
// 1
// 2
// 3
}
Insert cell
Insert cell
result_of_set = {
const iterable = new Set([1, 1, 2, 2, 3, 3]);

for (const value of iterable) {
return(value);
}
// 1
// 2
// 3
}
Insert cell
Insert cell
result_symbol = {
const iterable1 = {};
iterable1[Symbol.iterator] = function* () {
yield 1;
yield 2;
yield 3;
};

return([...iterable1]);
// expected output: Array [1, 2, 3]
}
Insert cell
Insert cell
Insert cell
result_while = {
let n = 0;
while (n < 7) {
n++;
}
return n;
}
Insert cell
Insert cell
Insert cell
result_switch= {
const expr = 'Яблоки';
switch (expr) {
case 'Апельсины':
return('Апельсины стоят 3.44$.');
break;
case 'Бананы':
return('Бананы стоят 2.73$.');
break;
case 'Яблоки':
return('Яблоки стоят 1.55$.');
break;
default:
return(`К сожалению нет ${expr}.`);
}
}
Insert cell
Insert cell
Insert cell
result_m = {
try {
return 'Начало запуска';
// ...здесь нет ошибок
return 'Конец запуска';
} catch (err) {
return 'Catch игнорируется, потому что нет ошибок';
}
}
Insert cell
Insert cell
result_n = {
try {
throw new Error('oops'); // ...здесь ошибка
} catch (err) {
return 'Catch работал, потому что есть ошибка';
}
}
Insert cell
Insert cell
result_t = {
try {
throw new Error('oops');
}
finally {
return 'finally';
}
}
Insert cell

Purpose-built for displays of data

Observable is your go-to platform for exploring data and creating expressive data visualizations. Use reactive JavaScript notebooks for prototyping and a collaborative canvas for visual data exploration and dashboard creation.
Learn more