const SumNumbers = (a, b) => {
if (typeof a !== 'number' || typeof b !== 'number') {
return "a and b не числа!"
}
if (a <= 0 || b <= 0) {
return "Неприемливые числа"
}
return a + b
}
let sum = SumNumbers(55, 5)
console.log(sum)❤1🔥1
Forwarded from КосмоНавт (KosmoNavt.cpp)
Please open Telegram to view this post
VIEW IN TELEGRAM
🥰2❤1
const myObject = {
x: 12,
y: true,
z: 'hi'
}
Object.values(myObject).forEach(values => {
console.log(values)
})const myObject = {
x: 12,
y: true,
z: 'hi'
}
Object.keys(myObject).forEach(keys => {
console.log(keys)
})Методы keys и values для объектов
🔥2🤔1
Начал изучать классы и прототипы
class Comment {
constructor(text) {
this.text = text
this.votesQty = 0
}
upvote() {
this.votesQty += 1
}
}
const firstComment = new Comment('First comment')❤1👍1🔥1🥰1
https://doka.guide/js/array-reduce/
Чувствую, что с этим я ебаться буду долго...
Дока
.reduce() — JavaScript — Дока
Швейцарский нож для работы с массивами. Заменяет все остальные методы (не повторяйте дома).
😭2
fetch('https://jsonplaceholder.typicode.com/posts')
.then((response) => response.json())
.then((json) => console.log(json));const timerPromise = () =>
new Promise((resolve, reject) =>
setTimeout(() => resolve(), 2000))
const asyncFn = async () => {
console.log('Timer starts')
const startTime = performance.now()
await timerPromise()
const endTime = performance.now()
console.log('Timer ended', endTime - startTime)
}
asyncFn()