function BigUser() {
this.name = "John";
return { name: "Godzilla" }; // <-- returns this object
}
alert( new BigUser().name ); // Godzilla, got that objectfunction BigUser(){
this.name = "Fotima"
return {name: "Godzila"};
}
alert(new BigUser().name );
console.log(new BigUser())function BigUser(){
this.name = "Fotima"
return {name: "Godzila"};
}
alert(new BigUser().name );
console.log(new BigUser().name)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)
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)
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:
There are other kinds of objects in JavaScript: functions, for example, are objects.
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.
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.