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
On this page of the site you can watch the video online Object Literal vs. Object Constructor in JavaScript - JavaScript Tutorial 75 with a duration of hours minute second in good quality, which was uploaded by the user ChidresTechTutorials 23 January 2018, share the link with friends and acquaintances, this video has already been watched 4,198 times on youtube and it was liked by 88 viewers. Enjoy your viewing!