In this #FullStackWebDevelopment tutorial series video, We are going to learn about basics of #javascripts #objects, how can we work with them to compact our code and make it reusable.
JavaScript object is a collection of named values. These objects are quite different from JavaScript’s primitive data-types(Number, String, Boolean, null, undefined and symbol) in the sense that while these primitive data-types all store a single value each (depending on their types).
Objects are more complex and each object may contain any combination of these primitive data-types as well as reference data-types. Loosely speaking, objects in JavaScript may be defined as an unordered collection of related data, of primitive or reference types, in the form of “key: value” pairs. These keys can be variables or functions and are called properties and methods, respectively, in the context of an object.
An object can be created with figure brackets {…} with an optional list of properties. A property is a “key: value” pair, where a key is a string (also called a “property name”), and value can be anything.
For example:
var student1 = {
name : "Boris Johnson",
rollNo. : "07",
DOB : "19-06-1964"
display: function() {
return “Hii, I’m “ + this.name + “ bearing Roll no. “ + this.rollNo + “ and my date of birth is “ + this.DOB;}
};
console.log(student1.display());
In the above example “name”, “Roll no.”, “DOB” are all keys which are the property of the object “student” and “Boris Johnson”, “07” and “19-06-1964”(which are all string type) are values of these keys respectively. We separate keys and values of an object with a comma. We can also create a function inside of an object. Here the key is “display” and function() is the value. this keyword is used to refer to the property of the specified object. If we are inside of a function and want to refer to other properties inside of an object we use this keyword.
There are two other ways we can work with objects:
A) Creating new empty object: var student1 = {};
student1.name : "Boris Johnson";
student1.rollNo. : "07";
student1.DOB : "19-06-1964";
B) Object Constructor: It creates an object wrapper for the given value. This, used in conjunction with the “new” keyword allows us to initialize new objects.
Example:
var student1 = new object();
student1.name : "Boris Johnson";
student1.rollNo. : "07";
student1.DOB : "19-06-1964";
----------------------------
Week 1 : Day 7
Section 5 : Learning to Code With Javascript
Tutorial 41: Javascript Objects
----------------------------
Do subscribe and hit Bell Icon
----------------------------
Follow us in social media handles for opportunities and code related support.
Instagram: / wb.web
Facebook: / wbweb
Twitter: / wbweb_in
LinkedIn: / wbweb
----------------------------
Got a question on the topic? Please share it in the comment section below and our experts will answer it for you.
For more information, please write back to us at hi@wbweb.co.in or call us at IND: 7077568998
After completing the course, write to biswabijaya@wbweb.co.in for internship or freelancing opportunities.
For consultation or partnership related queries drop a mail to hi@wbweb.co.in.
On this page of the site you can watch the video online 41. Javascript Objects - Full stack web development Course with a duration of hours minute second in good quality, which was uploaded by the user WB Web Development Solutions 26 May 2018, share the link with friends and acquaintances, this video has already been watched 20,676 times on youtube and it was liked by 289 viewers. Enjoy your viewing!