Skip to content

Latest commit

 

History

History
44 lines (39 loc) · 2.16 KB

properties.md

File metadata and controls

44 lines (39 loc) · 2.16 KB
chapter pageNumber titleIndex
अध्याय ९
५९
९.१

गुणहरू

वस्तुको प्रोपर्टी propertyName हो: propertyValue जोडी, जहाँ गुण नाम स्ट्रिङ मात्र हुन सक्छ । यदि यो स्ट्रिङ होइन भने, यो एक स्ट्रिंगमा फ्याँकिन्छ। वस्तु वा पछि सिर्जना गर्दा तपाईँले गुण निर्दिष्ट गर्न सक्नुहुन्छ । अल्पविरामद्वारा छुट्याइएको शून्य वा बढी गुणहरू हुन सक्छन्।

let language = {
  name: "JavaScript",
  isSupportedByBrowsers: true,
  createdIn: 1995,
  author: {
    firstName: "Brendan",
    lastName: "Eich",
  },
  // Yes, objects can be nested!
  getAuthorFullName: function () {
    return this.author.firstName + " " + this.author.lastName;
  },
  // Yes, functions can be values too!
};

निम्न कोडले कसरी सम्पत्तिको मूल्य प्राप्त गर्ने भनेर देखाउँछ।

let variable = language.name;
// variable now contains "JavaScript" string.
variable = language["name"];
// The lines above do the same thing. The difference is that the second one lets you use litteraly any string as a property name, but it's less readable.
variable = language.newProperty;
// variable is now undefined, because we have not assigned this property yet.

निम्न उदाहरणले कसरी नयाँ गुण थप्ने वा अवस्थित गुण परिवर्तन गर्ने भनेर देखाउँछ।

language.newProperty = "new value";
// Now the object has a new property. If the property already exists, its value will be replaced.
language["newProperty"] = "changed value";
// Once again, you can access properties both ways. The first one (dot notation) is recomended.