Tech
News
Videos
Forums
Jobs
Books
Events
More
Interviews
Live
Learn
Training
Career
Members
Blogs
Challenges
Certification
Contribute
Article
Blog
Video
Ebook
Interview Question
Collapse
Feed
Dashboard
Wallet
Learn
Achievements
Network
Refer
Rewards
SharpGPT
Premium
Contribute
Article
Blog
Video
Ebook
Interview Question
Register
Login
Exercice 1 of JavaScript Objects With String
WhatsApp
Ankur Mishra
4y
7.2k
0
0
100
Article
Introduction
Using vehicles as an example, if a vehicle is an object and color and speed are its properties then we can add properties to add an object by using the "this" keyword followed by the dot (.) operator.
Now let's extend the object function, myobject, to contain two properties, each containing a string of text.
Syntax
The properties defined in the code above can be accessed by the given code:
Now let's work with a String Object
We have learned from the preceding about String objects and various properties. There are some important properties like length and prototype. The length property specifies the number of characters in a string, while the prototype adds properties and methods to an object. Let's do some exercises.
See the given code
In the code above a function named employee is created with the three parameters name, jobtitle, and salary. Two objects emp1 and epm2 of the employee type are created using the "new" keyword and values are passed for the specified parameters. The emp2 object has an additional property, named doj, by using the prototype property.
See the output for the following code:
So this was a simple example of a String object. Do more exercises and be connected with your questions.
JavaScript
JavaScript Objects
JavaScript String
Up Next
Ebook Download
View all
Voice of a Developer: JavaScript From Scratch
Read by 11k people
Download Now!
Learn
View all
Foreantech
Foreantech - A complete online solution company.
Membership not found