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

Publicado el: 23 enero 2018
en el canal de: 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


En esta página del sitio puede ver el video en línea Object Literal vs. Object Constructor in JavaScript - JavaScript Tutorial 75 de Duración hora minuto segunda en buena calidad , que subió el usuario ChidresTechTutorials 23 enero 2018, comparta el enlace con amigos y conocidos, en youtube este video ya ha sido visto 4,198 veces y le gustó 88 a los espectadores. Disfruta viendo!