JavaScript Variables and Objects: Passed by Value or Reference?

preview_player
Показать описание
In this video we take a look at a simple concept, but a concept that is important to understand in JavaScript. Are primitive values and objects passed to other variables by value or by reference? We will illustrate the concept and then take a look at several code examples.

For a complete list of all our tutorials:

Take the Learn Modern JavaScript: Getting Started or the Learn Modern JavaScript: Advanced Topics courses at a huge discount:
Рекомендации по теме
Комментарии
Автор

finally find a teacher whose teaching skills that I can understand so well, really thank you for that !

xiaosage
Автор

Thank you for creating these insightful tutorials for us. These tutorials help us a lot.

rotrose
Автор

I understand how pass by value is different from pass by reference now, thanks

blackpurple
Автор

what about arrays?
as arrays are same as object, i think it is also pass by reference ?
reply please?

rajeshnaika
Автор

Javascript is always pass by value. Pass by reference does not exist in JavaScript. When you remind yourself about the fact that an object and a reference to that object are 2 *independent* things, it will make more sense. I suppose we've been conflating and object "reference" and passing function arguments "by reference."

When passing a object reference, the *value* of that reference (e.g. the address of the object) is copied and that copy is passed - This is the definition of pass by value. "Pass by reference" means the original reference, not a copy, is passed. Here's the litmus test: In the called function assign a different object to the reference variable. If the original reference now points to this different object then you have pass by reference. But this does not happen in JavaScript.

Of course you can change the object's properties, because the reference copy is pointing to the same object. But that is not germane. Rather, "Pass by xxxx" means - whatever you're passing, if it a copy it is "by value", if it is the original it is "by reference".

robertjones
Автор

Thank you very much. How long will it take me to become employable? I've been learning for about 4 days when I get a chance. like 3 hours After work because I dont have a computer and i do it at the library and as many hours as I can on my 2 days off. How long will it take me? thank you.

nelsonjimenez
Автор

please share link of slice as well as splice

jainshilpi