javascript sources
1 subscriber
1 photo
1 link
Hello world
Download Telegram
Forwarded from coding with ☕️
const arr = ["Coding", "With",];
arr.push("Even");
console.log(arr)
Forwarded from coding with ☕️
Javascript Array Methods
Forwarded from coding with ☕️
let set = new Set();

let john = { name: "John" };
let pete = { name: "Pete" };
let mary = { name: "Mary" };

// visits, some users come multiple times
set.add(john);
set.add(pete);
set.add(mary);
set.add(john);
set.add(mary);

// set keeps only unique values
alert( set.size ); // 3

for (let user of set) {
alert(user.name); // John (then Pete and Mary)
}
Forwarded from coding with ☕️
let user = {
name: "John",
age: 30,

toString() {
return `{name: "${this.name}", age: ${this.age}}`;
}
};

alert(user); // {name: "John", age: 30}
Forwarded from coding with ☕️
Ob'ektlarni JSONga aylantirish uchun JSON.stringify.
JSON.parse JSON-ni ob'ektga qaytadan aylantirish uchun.
Forwarded from coding with ☕️
let student = {
name: 'John',
age: 30,
isAdmin: false,
courses: ['html', 'css', 'js'],
spouse: null
};

let json = JSON.stringify(student);


console.log(student)
Forwarded from coding with ☕️
alert( Math.max(3, 5, 1) ); // 5
Forwarded from coding with ☕️
coding with ☕️
alert( Math.max(3, 5, 1) ); // 5
Math.max(3, 5, 1) funksiyasi berilgan sonlar orasidan eng kattasini qaytaradi.
Forwarded from coding with ☕️
JavaScript-da rest operatori (...) vazifasi
Rest operatori (...) bir nechta argument yoki massiv elementlarini bitta o‘zgaruvchiga yig‘ish uchun ishlatiladi. U asosan funksiya argumentlarini yoki massiv va obyektlardan ma'lumot olish uchun ishlatiladi.
Forwarded from coding with ☕️
function logger(a, b, ...rest) {
console.log(a);
console.log(b);
console.log(rest);
}
logger(12, 10, 1, 2, 3, 4, 5, 6);
Forwarded from coding with ☕️
coding with ☕️
function logger(a, b, ...rest) { console.log(a); console.log(b); console.log(rest); } logger(12, 10, 1, 2, 3, 4, 5, 6);
Funksiya parametrlari quyidagicha taqsimlanadi:

a = 12
→ Birinchi argument

b = 10
→ Ikkinchi argument

...rest = [1, 2, 3, 4, 5, 6]
→ Qolgan argumentlar massivga yig‘iladi
Forwarded from coding with ☕️
Rest operatori (...rest) barcha ortiqcha argumentlarni massiv sifatida saqlaydi.

Logger funksiyasiga nechta argument bersangiz ham, a va b birinchi ikkita qiymatni oladi, qolganlari rest massiviga tushadi.
Forwarded from coding with ☕️
Y - tepa, pasga
X - chap, oʻnga
Forwarded from coding with ☕️
const cards = document.querySelectorAll(".catalog_box"),
textInfo = document.querySelector(".text");

cards.forEach(card => {
card.addEventListener("mousemove", (e) => {
let half = card.clientWidth / 2
let x = e.offsetX - half
let y = e.offsetY - half
textInfo.innerHTML = `${x}px | ${y}px`
card.style.transform = `rotateY(${x/4}deg) rotateX(${-y/4}deg)`
})
card.onmouseout = () => card.style.transform = `rotate(0)`
})
Forwarded from coding with ☕️
//ORIENTED OPERATING PROGRAMMING

class Typing {
constructor({el, interval, delay}){
this.el = document.querySelector(el);
this.interval = interval || 500
this.delay = delay == undefined ? 1000 : delay
this.text = this.el.innerHTML.trim()
this.el.innerHTML = ""
setTimeout(() => this.write(i), this.delay);
}
write(i = 0){
this.el.innerHTML += this.text[i]
i++;
if (i < this.text.length) {
setTimeout(() => this.write(i), this.interval);
}

}
}
new Typing({
el: ".header__content h1" ,
interval: 300,
delay:1000
});
Forwarded from coding with ☕️
DOM
Forwarded from coding with ☕️
document.body.style.background = 'red'; // make the background red

setTimeout(() => document.body.style.background = '', 3000); // return back
Forwarded from coding with ☕️
const element = document.getElementById('myElement');
console.log(element.clientWidth); // Elementning ko'rinadigan kengligi
console.log(element.clientHeight); // Elementning ko'rinadigan balandligi