javascript sources
1 subscriber
1 photo
1 link
Hello world
Download Telegram
Forwarded from coding with ☕️
let user = {
name: "John",
age: 30,

sayHi() {
alert(user.name); // "user" instead of "this"
}

};
Forwarded from coding with ☕️
function sayHi() {
alert( this.name );
}
Forwarded from coding with ☕️
function BigUser() {

this.name = "John";

return { name: "Godzilla" }; // <-- returns this object
}

alert( new BigUser().name ); // Godzilla, got that object
Forwarded from coding with ☕️
function BigUser(){
this.name = "Fotima"

return {name: "Godzila"};
}
alert(new BigUser().name );
console.log(new BigUser())
Forwarded from coding with ☕️
`with "New Operator" we can call in "console.log" with " ( ) "
Forwarded from coding with ☕️
function BigUser(){
this.name = "Fotima"

return {name: "Godzila"};
}
alert(new BigUser().name );
console.log(new BigUser().name)
Forwarded from coding with ☕️
let id = Symbol("id");
alert(id.description);
console.log(Symbol())
Forwarded from coding with ☕️
JavaScriptda primitive (oddiy) turlar bu oddiy qiymatlar bo‘lib, ular obyekt emas, o‘zgaruvchining o‘zida saqlanadi va o‘zgarmas (immutable) bo‘ladi.

JavaScriptdagi primitive turlar:
String – "hello", 'world'

Number – 42, 3.14, -10

Boolean – true, false

Undefined – let x; (qiymati yo‘q)

Null – let y = null; (bo‘sh qiymat)

Symbol – Symbol("id") (noyob identifikator)

BigInt – 12345678901234567890n (katta sonlar uchun)
Forwarded from coding with ☕️
A primitive

Is a value of a primitive type.
There are 7 primitive types: string, number, bigint, boolean, symbol, null and undefined.


An object

Is capable of storing multiple values as properties.
Can be created with {}, for instance:
{name: "John", age: 30}.

There are other kinds of objects in JavaScript: functions, for example, are objects.
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)
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)
Forwarded from coding with ☕️
let num = Number("123"); // convert a string to number
Forwarded 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 ☕️
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}