javascript sources
1 subscriber
1 photo
1 link
Hello world
Download Telegram
Forwarded from coding with ☕️
Object
Forwarded from coding with ☕️
let user = {     // an object
name: "John", // by key "name" store value "John"
age: 30 // by key "age" store value 30
};
Forwarded from coding with ☕️
function makeUser(name, age) {
return {
name: name,
age: age,
// ...other properties
};
}

let user = makeUser("John", 30);
alert(user.name); // John
Forwarded from coding with ☕️
let user = {
name: "John",
age: 30
};

user.sayHi = function() {
alert("Hello!");
};

user.sayHi(); // Hello!
Forwarded from coding with ☕️
let user = {
name: "John",
age: 30,

sayHi() {
// "this" is the "current object"
alert(this.name);
}

};

user.sayHi(); // John
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.