Object Literal vs. Object Constructor in JavaScript - JavaScript Tutorial 75

Publié le: 23 janvier 2018
sur la chaîne: ChidresTechTutorials
4,198
88

Notes for You:: Object Literal vs. Object Constructor in JavaScript - JavaScript Tutorial 75
Creating objects using Object literal and Object constructor are quite similar.

But there are some differences:

1) Syntactic difference:
while creating objects using object literal, we use pair of flower brackets instead of "new Object()".

a) Creating a new object using Object constructor:
Syntax: var objectName = new Object();
Example: var rect1 = new Object();

b) Creating a new object using Object literal:
Syntax: var objectName = {};
Example: var rect1 = {};


2) Execution difference:

a) Execution with Object constructor:
Example: var rect1 = new Object();
When the system finds new keyword on the RHS of equal to symbol, it follows 4 steps

i) Creates a new empty object
ii) Sets the value of implicit prototype “__proto__” of a new empty object to its Constructor.prototype
iii) Calls its Constructor function with “newly created memory location address” with “list of arguments” if passed
iv) Returns the reference of new object, if Constructor function does not return anything explicitly


b) Execution with Object literal:
Example: var rect1 = {};
When the system finds {} on the RHS of equal to symbol, it follows 3 steps

i) Creates a new empty object
ii) Sets the value of implicit prototype “__proto__” of a new empty object to Object.prototype
iii) Returns the reference of new object


Note: It is recommended to use {} instead of "new Object()"
1. You type less.
2. Execution speed.
3. Vulnerability in overriding Object constructor.

=========================================

Follow the link for next video:
JavaScript Tutorial 76 - Advantages of Object Literal notation in JavaScript
   • Advantages of JavaScript Object Liter...  

Follow the link for previous video:
JavaScript Tutorial 74 - How to Set or Get Object properties in JavaScript
   • How to set & get Object Properties in...  

=========================================

JavaScript Tutorials Playlist:-
   • JavaScript Tutorials  

=========================================
Watch My Other Useful Tutorials:-

jQuery Tutorials Playlist:-
   • jQuery Tutorials  

jQuery UI Tutorials Playlist:-
   • jQuery UI Tutorials  

Bootstrap Tutorials Playlist:-
   • Bootstrap4 Tutorials  

=========================================

► Subscribe to our YouTube channel:
   / chidrestechtutorials  

► Visit our Website:
https://www.chidrestechtutorials.com

=========================================
Hash Tags:-
#ChidresTechTutorials #JavaScript #JavaScriptTutorial


Sur cette page du site, vous pouvez voir la vidéo en ligne Object Literal vs. Object Constructor in JavaScript - JavaScript Tutorial 75 durée heure minute seconde en bonne qualité , qui a été Téléchargé par l'utilisateur ChidresTechTutorials 23 janvier 2018, Partagez le lien avec vos amis et connaissances, sur youtube cette vidéo a déjà été regardée 4,198 fois et il a aimé 88 téléspectateurs. Bon visionnage!