This document discusses JavaScript prototype objects. It explains that in JavaScript, each object contains a prototype object that allows objects to acquire properties and methods from one another. It also explains that whenever a function is created, a prototype property is automatically added to that function. This property holds a constructor property and a prototype object. The document provides an example of adding a new method to a constructor function's prototype. It also discusses prototype chaining and how an object's prototype may contain another prototype object.
This deck provides an overview of key concepts in Objective-C including MVC architecture, classes, instances, methods, properties, delegates and protocols, Xcode IDE, and common classes and terms. It explains that MVC separates applications into modular and replaceable models, views, and controllers. Classes define properties and methods while instances contain property values. Methods are messages sent to objects. Properties use accessor methods. Header files define public interfaces while implementation files contain private code. Delegates and protocols allow communication between decoupled components.
Constructors In Java – Unveiling Object CreationGeekster
The document discusses constructors in Java, which are special methods used for initializing objects. It explains their syntax, types (default, parameterized, and copy constructors), and their significance in ensuring that objects are in a valid state upon creation. Additionally, it contrasts constructors with regular methods, highlighting their roles in object initialization and encapsulation.
1. The document discusses the concepts of object-oriented programming including classes, objects, and member functions.
2. A class defines the data attributes and behaviors of a type of object. An object is an instance of a class that stores its own set of data attributes and can access class member functions.
3. The example defines a Book class with private data attributes (name, pages, price) and public member functions to change attribute values and display an object's attributes.
22519 - Client-Side Scripting Language (CSS) chapter 1 notes .pdfsharvaridhokte
JavaScript, created by Brendan Eich in 1995, is a programming language primarily used for dynamic content in HTML pages. It features capabilities such as user interaction, data validation, and support for dynamic typing, object-oriented programming, and regular expressions. JavaScript can be embedded directly in HTML or included as an external file, and it allows manipulation of the Document Object Model (DOM) to alter the way web pages are displayed and interacted with.
Javascriptinobject orientedway-090512225827-phpapp02Sopheak Sem
The document discusses JavaScript closures. It explains that a closure occurs when an inner function is returned from an outer function and still has access to the outer function's variables even after it has returned. This is because closures combine a function and the environment in which that function was created, including any local variables that were in scope. As a result, the inner function can access and use those variables even though the outer function has finished executing. An example is provided to demonstrate how a function can return another function that still has access to the outer function's variables through a closure.
Object-oriented programming uses classes and objects to organize code and data. A class defines attributes like variables and methods like functions that belong to the class. An object is an instance of a class that stores the attribute values and allows calling methods. Classes help create reusable code through objects and allow encapsulation of data within classes.
Object-oriented programming uses classes and objects to organize code and data. A class defines attributes like variables and methods like functions that belong to the class. An object is an instance of a class that stores the attribute values and can call the methods. Classes allow code and data to be bundled into reusable components to build robust programs with less code and faster development time compared to procedural programming.
The document provides a comprehensive overview of object-oriented programming (OOP) in PHP, covering core concepts such as classes, objects, encapsulation, inheritance, and polymorphism. It explains the definition and utilization of objects, visibility levels of properties and methods, constructors, destructors, and the process of cloning objects. Additional details include method creation, property management, and an exploration of advanced functionalities like constructor overloading and overriding methods.
The document discusses object-oriented programming concepts in JavaScript, including key principles like objects, classes, encapsulation, inheritance, and polymorphism. It compares JavaScript's OOP capabilities to other languages and provides examples of how to create and use objects, constructors, and inheritance in JavaScript. Additionally, it covers JavaScript data types, error handling, and suggestions for improving performance in JavaScript applications.
This document discusses object-oriented programming concepts in Objective-C, including classes and objects, properties, methods, interfaces, implementations, memory management, and properties. It provides code examples for defining a Car class with properties like model and methods like drive(). It demonstrates creating instances of the Car class, setting properties, and calling methods.
(An Extended) Beginners Guide to Object Orientation in PHPRick Ogden
The document is a beginner's guide to object-oriented programming (OOP) in PHP, explaining concepts such as classes, objects, methods, properties, encapsulation, and inheritance. It emphasizes the importance of understanding entities as self-sufficient objects and provides insights on how to create and manage these constructs within the PHP environment. Additionally, it covers advanced topics like fluent interfaces and singleton patterns, while also noting the efficiency drawbacks of OOP in smaller projects.
This document provides an overview of key concepts in Android development including data types, classes and objects, methods, conditional statements, and intents. It explains that data types in Android are the same as in Java, including primitive types like int and double, and non-primitive types like String. Classes are blueprints that define objects with attributes and methods, and an object is an instance of a class. Methods are blocks of code that perform tasks. Conditional statements like if/else execute code based on conditions. Intents allow activities to communicate by passing messages and data between each other to start new activities or perform actions. Explicit intents specify a target component while implicit intents declare a general action.
Swift Tutorial Part 2. The complete guide for Swift programming languageHossam Ghareeb
This document provides a comprehensive guide on programming in Swift, covering essential concepts such as classes, inheritance, computed properties, and protocols. It explains the syntax for defining classes and their attributes, the differences between structures and classes, and provides examples of operator functions and generics. The guide also delves into advanced topics like property observers, type casting, and extensions, ensuring a well-rounded understanding of Swift programming.
1. Descriptive programming in QTP allows test scripts to run without relying on an object repository by directly describing and identifying objects.
2. There are several ways to do descriptive programming in QTP, including initializing variables to represent objects and using properties to describe them for identification and interaction.
3. Examples show how to use descriptive programming to search on Google without using an object repository, by directly describing the search box, button, and page and specifying the interactions between them.
The document provides a comprehensive overview of Objective-C, its origin, and key features as an object-oriented programming language developed in the early 1980s. It details the differences between Objective-C and C, explains object-oriented concepts like classes and methods, and covers memory management, constructors, inheritance, and threading. Additionally, it compares Objective-C with C++ and includes examples to illustrate its syntax and usage.
This document provides an introduction to object-oriented programming concepts. It defines object-oriented programming as a way to conceptualize a program as interacting objects. Key concepts discussed include:
- Classes define templates for objects and their properties and behaviors.
- Objects are instantiated from classes and represent specific instances.
- Inheritance allows new classes to inherit properties from parent classes.
- Encapsulation groups related properties and methods together within objects.
- Polymorphism allows methods to perform different actions depending on an object's properties.
The document provides an introduction to design patterns developed by the Gang of Four (GoF). It discusses several common design patterns in JavaScript like the constructor pattern, module pattern, singleton pattern, observer pattern, mediator pattern, prototype pattern, command pattern, facade pattern, and mixin pattern. For each pattern, it explains the problem it addresses, provides an example implementation, and notes advantages and disadvantages of the pattern. The overall document serves as a high-level overview of fundamental design patterns and their usage in JavaScript applications.
This document provides an introduction to C++ and object-oriented programming (OOP), explaining fundamental concepts such as classes, objects, methods, and constructors. It highlights the advantages of OOP over procedural programming, including better code maintainability and reusability. Additionally, it covers access specifiers and provides examples of creating classes and objects in C++.
The document discusses object-oriented programming concepts like abstraction, encapsulation, and classes using C++ as an example. It explains that a class combines data representation and methods to manipulate the data. A class declaration describes the data members and public interface, while method definitions provide the implementation details. Access control keywords like private and public control access to class members. Member functions allow manipulating private data through a public interface.
The document provides an overview of ActionScript 3.0 fundamentals including the ActionScript Virtual Machine, data types, classes, inheritance, interfaces, and object-oriented programming concepts in ActionScript. It discusses topics such as variables, functions, conditional statements, loops, scope, packages, namespaces, and more. The document is intended as educational material for learning the basics of the ActionScript 3.0 programming language.
This document provides an overview of object-oriented programming concepts including abstraction, encapsulation, classes, objects, methods, constructors, inheritance, polymorphism, and interfaces. It explains that classes act as blueprints for objects, describing their data and behaviors. Objects are instances of classes that have state stored in attributes and behaviors defined by methods. Key features of OOP like inheritance, encapsulation, and polymorphism are discussed at a high level.
The document discusses classes and objects in C++. It defines what a class is - a blueprint for an object that contains data members and member functions. An object is an instance of a class that allocates memory. The document explains how to define a class with public and private members, create objects of a class, and access class members through objects using dot operators. It also covers constructors and how they initialize objects automatically upon creation.
The document provides information on Java OOP concepts including objects, classes, inheritance, polymorphism, abstraction, and encapsulation. It defines objects as entities with state and behavior, and classes as collections of objects. Inheritance allows objects to acquire properties of parent objects. Polymorphism allows one task to be performed in different ways. Abstraction hides internal details and shows functionality, while encapsulation binds code and data together into a single unit.
The document provides an overview of iOS application development using Objective-C. It discusses that Objective-C adds object-oriented programming to C by incorporating Smalltalk-style messaging. It also notes that Objective-C is the main programming language used by Apple for iOS and OS X operating systems. The document then covers Objective-C syntax, classes, memory management using reference counting, protocols, blocks, and exception handling.
Encapsulation isolates the internal complexity of an object's operation from the rest of the application. Inheritance allows one class to reuse the state and behavior of another class. Polymorphism allows a client to treat different objects in the same way even if they were created from different classes and exhibit different behaviors.
Javascript allows interactive content on web pages and control of the browser and document. It is an interpreted scripting language that is cross-platform but support varies. Javascript can provide interactive content, control document appearance and content, and interact with the user through event handlers.
Unlock the Secrets of Crypto Trading with FinanceWorld.io!
Are you ready to dive into the exciting world of cryptocurrency trading? This comprehensive course by FinanceWorld.io is designed for beginners and intermediate traders who want to master the fundamentals of crypto markets, technical analysis, risk management, and trading strategies.
What you’ll learn:
Introduction to blockchain and cryptocurrencies
How crypto markets work
Setting up wallets and trading accounts securely
Understanding exchanges and order types
Reading charts and technical analysis basics
Essential indicators and market signals
Risk management and portfolio diversification
Real-life trading strategies and case studies
Common mistakes and how to avoid them
Who should view this course?
Aspiring crypto traders
Investors seeking additional income sources
Anyone curious about the future of decentralized finance
Why FinanceWorld.io?
Our experts make complex concepts simple, helping you gain the confidence to navigate volatile markets and capitalize on opportunities.
Ready to start your crypto journey?
View this slide deck now and take your first step towards becoming a successful crypto trader with FinanceWorld.io!
More Related Content
Similar to 13_User_Defined_Objects.pptx objects in javascript (20)
The document provides a comprehensive overview of object-oriented programming (OOP) in PHP, covering core concepts such as classes, objects, encapsulation, inheritance, and polymorphism. It explains the definition and utilization of objects, visibility levels of properties and methods, constructors, destructors, and the process of cloning objects. Additional details include method creation, property management, and an exploration of advanced functionalities like constructor overloading and overriding methods.
The document discusses object-oriented programming concepts in JavaScript, including key principles like objects, classes, encapsulation, inheritance, and polymorphism. It compares JavaScript's OOP capabilities to other languages and provides examples of how to create and use objects, constructors, and inheritance in JavaScript. Additionally, it covers JavaScript data types, error handling, and suggestions for improving performance in JavaScript applications.
This document discusses object-oriented programming concepts in Objective-C, including classes and objects, properties, methods, interfaces, implementations, memory management, and properties. It provides code examples for defining a Car class with properties like model and methods like drive(). It demonstrates creating instances of the Car class, setting properties, and calling methods.
(An Extended) Beginners Guide to Object Orientation in PHPRick Ogden
The document is a beginner's guide to object-oriented programming (OOP) in PHP, explaining concepts such as classes, objects, methods, properties, encapsulation, and inheritance. It emphasizes the importance of understanding entities as self-sufficient objects and provides insights on how to create and manage these constructs within the PHP environment. Additionally, it covers advanced topics like fluent interfaces and singleton patterns, while also noting the efficiency drawbacks of OOP in smaller projects.
This document provides an overview of key concepts in Android development including data types, classes and objects, methods, conditional statements, and intents. It explains that data types in Android are the same as in Java, including primitive types like int and double, and non-primitive types like String. Classes are blueprints that define objects with attributes and methods, and an object is an instance of a class. Methods are blocks of code that perform tasks. Conditional statements like if/else execute code based on conditions. Intents allow activities to communicate by passing messages and data between each other to start new activities or perform actions. Explicit intents specify a target component while implicit intents declare a general action.
Swift Tutorial Part 2. The complete guide for Swift programming languageHossam Ghareeb
This document provides a comprehensive guide on programming in Swift, covering essential concepts such as classes, inheritance, computed properties, and protocols. It explains the syntax for defining classes and their attributes, the differences between structures and classes, and provides examples of operator functions and generics. The guide also delves into advanced topics like property observers, type casting, and extensions, ensuring a well-rounded understanding of Swift programming.
1. Descriptive programming in QTP allows test scripts to run without relying on an object repository by directly describing and identifying objects.
2. There are several ways to do descriptive programming in QTP, including initializing variables to represent objects and using properties to describe them for identification and interaction.
3. Examples show how to use descriptive programming to search on Google without using an object repository, by directly describing the search box, button, and page and specifying the interactions between them.
The document provides a comprehensive overview of Objective-C, its origin, and key features as an object-oriented programming language developed in the early 1980s. It details the differences between Objective-C and C, explains object-oriented concepts like classes and methods, and covers memory management, constructors, inheritance, and threading. Additionally, it compares Objective-C with C++ and includes examples to illustrate its syntax and usage.
This document provides an introduction to object-oriented programming concepts. It defines object-oriented programming as a way to conceptualize a program as interacting objects. Key concepts discussed include:
- Classes define templates for objects and their properties and behaviors.
- Objects are instantiated from classes and represent specific instances.
- Inheritance allows new classes to inherit properties from parent classes.
- Encapsulation groups related properties and methods together within objects.
- Polymorphism allows methods to perform different actions depending on an object's properties.
The document provides an introduction to design patterns developed by the Gang of Four (GoF). It discusses several common design patterns in JavaScript like the constructor pattern, module pattern, singleton pattern, observer pattern, mediator pattern, prototype pattern, command pattern, facade pattern, and mixin pattern. For each pattern, it explains the problem it addresses, provides an example implementation, and notes advantages and disadvantages of the pattern. The overall document serves as a high-level overview of fundamental design patterns and their usage in JavaScript applications.
This document provides an introduction to C++ and object-oriented programming (OOP), explaining fundamental concepts such as classes, objects, methods, and constructors. It highlights the advantages of OOP over procedural programming, including better code maintainability and reusability. Additionally, it covers access specifiers and provides examples of creating classes and objects in C++.
The document discusses object-oriented programming concepts like abstraction, encapsulation, and classes using C++ as an example. It explains that a class combines data representation and methods to manipulate the data. A class declaration describes the data members and public interface, while method definitions provide the implementation details. Access control keywords like private and public control access to class members. Member functions allow manipulating private data through a public interface.
The document provides an overview of ActionScript 3.0 fundamentals including the ActionScript Virtual Machine, data types, classes, inheritance, interfaces, and object-oriented programming concepts in ActionScript. It discusses topics such as variables, functions, conditional statements, loops, scope, packages, namespaces, and more. The document is intended as educational material for learning the basics of the ActionScript 3.0 programming language.
This document provides an overview of object-oriented programming concepts including abstraction, encapsulation, classes, objects, methods, constructors, inheritance, polymorphism, and interfaces. It explains that classes act as blueprints for objects, describing their data and behaviors. Objects are instances of classes that have state stored in attributes and behaviors defined by methods. Key features of OOP like inheritance, encapsulation, and polymorphism are discussed at a high level.
The document discusses classes and objects in C++. It defines what a class is - a blueprint for an object that contains data members and member functions. An object is an instance of a class that allocates memory. The document explains how to define a class with public and private members, create objects of a class, and access class members through objects using dot operators. It also covers constructors and how they initialize objects automatically upon creation.
The document provides information on Java OOP concepts including objects, classes, inheritance, polymorphism, abstraction, and encapsulation. It defines objects as entities with state and behavior, and classes as collections of objects. Inheritance allows objects to acquire properties of parent objects. Polymorphism allows one task to be performed in different ways. Abstraction hides internal details and shows functionality, while encapsulation binds code and data together into a single unit.
The document provides an overview of iOS application development using Objective-C. It discusses that Objective-C adds object-oriented programming to C by incorporating Smalltalk-style messaging. It also notes that Objective-C is the main programming language used by Apple for iOS and OS X operating systems. The document then covers Objective-C syntax, classes, memory management using reference counting, protocols, blocks, and exception handling.
Encapsulation isolates the internal complexity of an object's operation from the rest of the application. Inheritance allows one class to reuse the state and behavior of another class. Polymorphism allows a client to treat different objects in the same way even if they were created from different classes and exhibit different behaviors.
Javascript allows interactive content on web pages and control of the browser and document. It is an interpreted scripting language that is cross-platform but support varies. Javascript can provide interactive content, control document appearance and content, and interact with the user through event handlers.
Unlock the Secrets of Crypto Trading with FinanceWorld.io!
Are you ready to dive into the exciting world of cryptocurrency trading? This comprehensive course by FinanceWorld.io is designed for beginners and intermediate traders who want to master the fundamentals of crypto markets, technical analysis, risk management, and trading strategies.
What you’ll learn:
Introduction to blockchain and cryptocurrencies
How crypto markets work
Setting up wallets and trading accounts securely
Understanding exchanges and order types
Reading charts and technical analysis basics
Essential indicators and market signals
Risk management and portfolio diversification
Real-life trading strategies and case studies
Common mistakes and how to avoid them
Who should view this course?
Aspiring crypto traders
Investors seeking additional income sources
Anyone curious about the future of decentralized finance
Why FinanceWorld.io?
Our experts make complex concepts simple, helping you gain the confidence to navigate volatile markets and capitalize on opportunities.
Ready to start your crypto journey?
View this slide deck now and take your first step towards becoming a successful crypto trader with FinanceWorld.io!
6/18/25
Shop, Upcoming: Final Notes to Review as we Close Level One. Make sure to review the orientation and videos as well. There’s more to come and material to cover in Levels 2-3. The content will be a combination of Reiki and Yoga. Also energy topics of our spiritual collective.
Thanks again all future Practitioner Level Students. Our Levels so far are: Guest, Grad, and Practitioner. We have had over 5k Spring Views.
https://ldm-mia.creator-spring.com
This includes the overall cultivation practices of Rose prepared by:
Kushal Lamichhane (AKL)
Instructor
Shree Gandhi Adarsha Secondary School
Kageshowri Manohara-09, Kathmandu, Nepal
INDUCTIVE EFFECT slide for first prof pharamacy studentsSHABNAM FAIZ
The inductive effect is the electron-withdrawing or electron-donating effect transmitted through sigma (σ) bonds in a molecule due to differences in electronegativity between atoms.
---
🔹 Definition:
The inductive effect is the permanent shifting of electrons in a sigma bond caused by the electronegativity difference of atoms, resulting in partial charges within the molecule.
F-BLOCK ELEMENTS POWER POINT PRESENTATIONSmprpgcwa2024
F-block elements are a group of elements in the periodic table that have partially filled f-orbitals. They are also known as inner transition elements. F-block elements are divided into two series:
1.Lanthanides (La- Lu) These elements are also known as rare earth elements.
2.Actinides (Ac- Lr): These elements are radioactive and have complex electronic configurations.
F-block elements exhibit multiple oxidation states due to the availability of f-orbitals.
2. Many f-block compounds are colored due to f-f transitions.
3. F-block elements often exhibit paramagnetic or ferromagnetic behavior.4. Actinides are radioactive.
F-block elements are used as catalysts in various industrial processes.
Actinides are used in nuclear reactors and nuclear medicine.
F-block elements are used in lasers and phosphors due to their luminescent properties.
F-block elements have unique electronic and magnetic properties.
How payment terms are configured in Odoo 18Celine George
Payment terms in Odoo 18 help define the conditions for when invoices are due. This feature can split payments into multiple parts and automate due dates based on specific rules.
List View Components in Odoo 18 - Odoo SlidesCeline George
In Odoo, there are many types of views possible like List view, Kanban view, Calendar view, Pivot view, Search view, etc.
The major change that introduced in the Odoo 18 technical part in creating views is the tag <tree> got replaced with the <list> for creating list views.
OBSESSIVE COMPULSIVE DISORDER.pptx IN 5TH SEMESTER B.SC NURSING, 2ND YEAR GNM...parmarjuli1412
OBSESSIVE COMPULSIVE DISORDER INCLUDED TOPICS ARE INTRODUCTION, DEFINITION OF OBSESSION, DEFINITION OF COMPULSION, MEANING OF OBSESSION AND COMPULSION, DEFINITION OF OBSESSIVE COMPULSIVE DISORDER, EPIDERMIOLOGY OF OCD, ETIOLOGICAL FACTORS OF OCD, CLINICAL SIGN AND SYMPTOMS OF OBSESSION AND COMPULSION, MANAGEMENT INCLUDED PHARMACOTHERAPY(ANTIDEPRESSANT DRUG+ANXIOLYTIC DRUGS), PSYCHOTHERAPY, NURSING MANAGEMENT(ASSESSMENT+DIAGNOSIS+NURSING INTERVENTION+EVALUATION))
Vitamin and nutritional deficiency occurs when the body does not receive enough essential nutrients, such as vitamins and minerals, needed for proper functioning. This can lead to various health problems, including weakened immunity, stunted growth, fatigue, poor wound healing, cognitive issues, and increased susceptibility to infections and diseases. Long-term deficiencies can cause serious and sometimes irreversible health complications.
HistoPathology Ppt. Arshita Gupta for Diplomaarshitagupta674
Hello everyone please suggest your views and likes so that I uploaded more study materials
In this slide full HistoPathology according to diploma course available like fixation
Tissue processing , staining etc
VCE Literature Section A Exam Response Guidejpinnuck
This practical guide shows students of Unit 3&4 VCE Literature how to write responses to Section A of the exam. Including a range of examples writing about different types of texts, this guide:
*Breaks down and explains what Q1 and Q2 tasks involve and expect
*Breaks down example responses for each question
*Explains and scaffolds students to write responses for each question
*Includes a comprehensive range of sentence starters and vocabulary for responding to each question
*Includes critical theory vocabulary lists to support Q2 responses
How to use search fetch method in Odoo 18Celine George
The search_fetch is a powerful ORM method used in Odoo for some specific addons to combine the functionality of search and read for more efficient data fetching. It might be used to search for records and fetch specific fields in a single call. It stores the result in the cache memory.
Romanticism in Love and Sacrifice An Analysis of Oscar Wilde’s The Nightingal...KaryanaTantri21
The story revolves around a college student who despairs not having a red rose as a condition for dancing with the girl he loves. The nightingale hears his complaint and offers to create the red rose at the cost of his life. He sang a love song all night with his chest stuck to the thorns of the rose tree. Finally, the red rose grew, but his sacrifice was in vain. The girl rejected the flower because it didn’t match her outfit and preferred a jewellery gift. The student threw the flower on the street and returned to studying philosophy
3. Objects In JavaScript
Before learning about objects , we must first understand a very
important statement which is very commonly used for
JavaScript
Javascript is not a class based language but a prototype based language.
4. What Is Class Based Language?
A class-based language is based on two fundamental entities:
“classes” and “instances”.
Class:
• A class is a user-defined data type.
• It describes a family of objects that have the same set of methods and
properties.
• For example, the Employee class could represent the set of all employees.
• Languages like Java, C++,Python etc are all class based languages
5. What Is Class Based Language?
Instance:
• An instance, is the instantiation of a class.
• For example, Sachin could be an instance of the Employee class, representing
a particular individual as an employee
• An instance has exactly the same properties as its class (no more, no less).
6. What Is Prototype Based
Language?
• A prototype-based language, such as JavaScript, does not make this
distinction: it simply has objects.
• In simple words we can say that creating a class is not required in
prototype based languages before creating an object.
• A prototype-based language has the notion of a prototypical object
7. What Is Prototype Based
Language?
• A prototypical object is used as a template from which we get the
initial properties for a new object.
• And in JavaScript this prototypical object is called Object which
provides all the basic properties and methods like toString() , valueOf()
to new objects
• Then these new objects can further specify their own properties, either
when we create them or at run time.
8. Objects In JavaScript
In JavaScript an object is a non-primitive data type.
It is like any other variable, the only difference is that an object
holds data in terms of properties and actions in terms of
methods.
9. An Important Point !
In other programming languages like Java or C#, we need a class
to create an object of it.
In JavaScript, an object is a standalone entity because designing
class is not compulsory to create objects in JavaScript.
However from ES6 onwards we can create a class if we want that.
11. Object Constructor
The first way to create an object is with Object Constructor using
the new keyword.
Syntax:
let <obj_name>=new Object();
Example:
let myCar=new Object();
12. Adding Properties
Properties are data members of an object used to hold values .
We can attach properties to an object in 2 ways:
1. Using the dot notation.
2. Using [ ] brackets and specifying property name as string.
13. Adding Properties Using Dot Operator
1. Using the dot notation.
Syntax:
<obj_name>.<property_name>=value;
Example:
myCar.name=“Baleno”;
myCar.year=2018;
14. Adding Properties Using [ ] Operator
2. Using the [ ] operator.
Syntax:
<obj_name>[“<property_name>”]=value;
Example:
myCar[“name”]=“Baleno”;
myCar[“year”]=2018;
15. Which To Prefer When ?
As a beginner we might get confused between when to use dot
notation and when to use [ ].
The answer is very simple :
Always use dot notation as its is the best and recommended way
But there are 2 cases when we will have to use [ ] and they are:
1. When property name contains spaces.
2. When property name is stored in a variable.
16. Special Point !
When a property name contains spaces, we need to create it
using [ ]
and to access it also we have to use [ ] .
For example:
myCar[“reg no”]=“MP04CB2314”;
console.log(myCar[“reg no”]);
If we use dot operator it will be an error
17. Special Point !
When a property name is stored in a variable, we need to create as
well
as access it we need use [ ]
For example:
var str=“company”;
console.log(myCar[str]); // will show Maruti
console.log(myCar.str); // will show
undefined
18. Special Point !
Reading from a property that does not exist will result in
an undefined.
For example:
console.log(myCar.price); // undefined
19. Changing Property Value
To change the value of a property, we simply use the
assignment
operator
Example:
myCar[“name”]=“Baleno”;
myCar[“year”]=2018;
myCar[“name”]=“Ciaz”;
console.log(myCar.name);// Ciaz
console.log(myCar.year);// 2018
20. Deleting A Property
To delete a property from an object, we use the delete operator:
Example:
myCar[“name”]=“Baleno”;
myCar[“year”]=2018;
delete myCar.year;
console.log(myCar.name);// Baleno
console.log(myCar.year);// undefined
21. Checking Whether A Property Exists Or Not
To check if a property does exists in an object, we use a special
operator called the in operator:
Example:
myCar[“name”]=“Baleno”;
myCar[“year”]=2018;
delete myCar.year;
console.log(‘name’ in myCar);// true
console.log(‘year’ in myCar);// false
22. Iterating Over Properties
To iterate over all properties of an object without knowing
property
names, we use the for...in loop:
Syntax:
for (key in object) {
// executes the body for each key among object properties
}
Example:
myCar[“name”]=“Baleno”;
myCar[“year”]=2018;
for (let key in myCar)
23. Adding Methods
Methods can also be added to the object
A method is nothing but a function that will access/manipulate
object’s properties.
Methods can be part of object during creation or can be added
later
like properties
26. Nested Objects
We can assign another object as a property of an object.
Syntax:
<obj_name>.<obj_name>=new Object();
<obj_name>.<obj_name>.<property_name>=<value>;
Example:
myCar.stereo=new Object();
myCar.stereo.name=“Sony";
27. PROGRAM
Write a JavaScript code to access all the properties of
myCar objects and it’s nested object using for in loop
28. Creating Object Using Object Literal
The object literal is a simple way of creating an object and it is
done using { } brackets.
We can include key-value pair in { }, where key would be property
or method name and value will be value of property or definition
of the method.
We use comma (,) to separate multiple key-value pairs.
29. Creating Object Using Object Literal
Syntax:
let <obj_name>={
<prop_name>:<value>,
<prop_name>:<value>
};
Example:
let myCar={
company:”Maruti”,
year:2014
30. Adding Method Using Object Literal
Syntax:
let <obj_name>={ <func_name>:function(){
// body
}
};
Example:
let myCar={start:function(){
console.log(“starting the car”);
}
};
31. PROGRAM
Given the following object , write a for in loop to
calculate and print total marks
let student = { name: "Sumit“,age: 15, phy: 45,chem: 5
0,
maths: 65
};