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)
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)
A Set is a special type collection – “set of values” (without keys), where each value may occur only once.
Its main methods are:
new Set([iterable]) – creates the set, and if an iterable object is provided (usually an array), copies values from it into the set.
set.add(value) – adds a value, returns the set itself.
set.delete(value) – removes the value, returns true if value existed at the moment of the call, otherwise false.
set.has(value) – returns true if the value exists in the set, otherwise false.
set.clear() – removes everything from the set.
set.size – is the elements count.
Its main methods are:
new Set([iterable]) – creates the set, and if an iterable object is provided (usually an array), copies values from it into the set.
set.add(value) – adds a value, returns the set itself.
set.delete(value) – removes the value, returns true if value existed at the moment of the call, otherwise false.
set.has(value) – returns true if the value exists in the set, otherwise false.
set.clear() – removes everything from the set.
set.size – is the elements count.
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)
}
let user = {
name: "John",
age: 30,
toString() {
return `{name: "${this.name}", age: ${this.age}}`;
}
};
alert(user); // {name: "John", age: 30}Ob'ektlarni JSONga aylantirish uchun
JSON.stringify.JSON.parse JSON-ni ob'ektga qaytadan aylantirish uchun.let student = {
name: 'John',
age: 30,
isAdmin: false,
courses: ['html', 'css', 'js'],
spouse: null
};
let json = JSON.stringify(student);
console.log(student)
coding with ☕️
alert( Math.max(3, 5, 1) ); // 5
Math.max(3, 5, 1) funksiyasi berilgan sonlar orasidan eng kattasini qaytaradi.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.
function logger(a, b, ...rest) {
console.log(a);
console.log(b);
console.log(rest);
}
logger(12, 10, 1, 2, 3, 4, 5, 6);
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
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.
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)`
})