Forwarded from coding with ☕️
let john = {
name: "John",
sayHi: function() {
alert("Hi buddy!");
}
};
john.sayHi(); // Hi buddy!
One of the best things about objects is that we can store a function as one of its properties.Forwarded from coding with ☕️
Common binary operators:
Arithmetic: +, -, *, /, %
Assignment: =, +=, -=, *=, /=
Comparison: ==, !=, ===, !==, >, <, >=, <=
Logical: &&, ||
Bitwise: &, |, ^, <<, >>, >>>
Ternary: condition ? expr1 : expr2 (Special case, but still binary because of two expressions)
Arithmetic: +, -, *, /, %
Assignment: =, +=, -=, *=, /=
Comparison: ==, !=, ===, !==, >, <, >=, <=
Logical: &&, ||
Bitwise: &, |, ^, <<, >>, >>>
Ternary: condition ? expr1 : expr2 (Special case, but still binary because of two expressions)
Forwarded from coding with ☕️
Common unary operators:
+ (Unary plus, converts to number)
- (Unary negation, negates a number)
! (Logical NOT)
typeof (Returns type of a variable)
delete (Deletes object properties)
void (Evaluates an expression but returns undefined)
++ (Increment)
-- (Decrement)
+ (Unary plus, converts to number)
- (Unary negation, negates a number)
! (Logical NOT)
typeof (Returns type of a variable)
delete (Deletes object properties)
void (Evaluates an expression but returns undefined)
++ (Increment)
-- (Decrement)
Forwarded from coding with ☕️
let num = Number("123"); // convert a string to numberForwarded from coding with ☕️
const arr = ["Coding", "With", "Even"];
arr.pop();
console.log(arr)
Forwarded from coding with ☕️
const arr = ["Coding", "With",];
arr.push("Even");
console.log(arr)
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 ☕️
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 ☕️
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)`
})