Steve, you are amazing. You talk slowly and calm and clear. Your voice has a very calm sound and makes me want to listen to you even if you describe how to vivisect a frog. Plus, your name just reminded me that it is many months I didn't check if there is any new Berserk chapter out.
Another great video, Steve! I'm watching almost all of your videos throught my learning journey with JS. If I need to understand better a specific concept, I hurry to your channel. Keep going, you're doing an amazing job! 🤗 💖
I know this is an older video but could you explain a bit more about why just adding the line dog["age"]=14 didn't work? Woody was declared up at the top so I expected to see that one updated. Thanks!
If you do EITHER or BOTH of these: dog.age = 14; dog['age'] = 14; Then you will add a property called age to the object dog, if it doesn't exist, or update its value, if it already exists.
5:39: Are you adding the label "age" to the variable "cat" or is "age" a variable within a variable? My take is that ir'd be the same as I writing "age":"2" on line 3
cat and dog are variables that hold objects. Both objects have "properties" called "age". There are two ways to get or set the value of the property age. 1. Square bracket syntax with the property name in quotation marks. objectName["propertyName"] 2. dot notation - objectName.propertyName The square bracket syntax is what you MUST use if you are using a variable to hold the name of the property.
That really depends on the context and what you are adding - a method, or a primitive value, or an array. What objects are you adding them to? If you just have a couple objects and you want to add a property to each one... let obj1 = { }; let obj2 = { }; let obj3 = { }; obj1.prop = 1; obj2.prop = 1; obj3.prop = 1; You work with them each individually. If you have a method that you want to add to a lot of objects then you should think about adding that to the prototype for your objects.
Is "var" from line 7 the only element that would differentiate an array from adding a new label to an object as in line 16? The latter looks very similar to an array nomenclature in terms of using square brackets.
To create an array, use [ ] To create an object, use { } arrays use numbers to access their values objects use names / labels to access their values. BOTH objects and arrays can use the square bracket syntax to target their contents.
property has a single word definition ex { name :"User"}, if you want the key to be of two words i.e. User name instead of name you can define like this let user= { "User name" : "Named user", }; and access the property like this ----> console.log(user["User name"]); if i have understood your question correctly then this is what you were looking for
How can you add and isolate an object when adding it to an array, so if the elements in the array change, it doesn't change the original object? I tried putting the object in () like "pets=[cat, (dog)]" but that didn't isolate it.
Further, if you changed the object cat or the object dog then the contents of the pets array would now be pointing to the updated version of the objects.
Hey Steve if I wanted to delete any of my objects properties I would use delete Operator right? as is: delete cat.age; And how can I save the value in a var before I deleted it? Is this correct? var deleted = delete cat['age'];
The delete operator is how you would remove a property from an Object (if allowed). However, the delete operator does NOT return the value of what it is deleting. It only returns true or false. You would have to put the value into a variable BEFORE calling delete. var Obj = { }; Obj.myprop = 123; var temp = Obj.myprop; delete Obj.myprop;
What would be the main difference between using CONSOLE.LOG and DOCUMENT.WRITE? I have come across different positions with regard to those two commands. On one side, DOCUMENT.WRITE not being recommended and on the other side CONSOLE.LOG being used merely as a tool for developers. Then I found RETURN... Here is a CodeAcademy answer, which makes a lot of sense: www.codecademy.com/en/forum_questions/53121d097c82ca0a33003906
document.write( ) is a way to add new content to the source of an html file WHILE THE HTML FILE IS LOADING. This is NOT recommended. Use the DOM methods to add new HTML to your page after the DOMContentLoaded event has occurred. Document.write( ) does NOTHING after the page has finished loading. Console.log( ) is used to write messages to the console. This is for development use only.
It would be helpful if you could walk through how objects within objects (or functions within objects) can be called and updated.
Thanks for the suggestion. I will add that to my list of future videos.
I have added that video now if you are still interested - ruclips.net/video/AqgVLYpBWG8/видео.html
@@SteveGriffith-Prof3ssorSt3v3 you'r really good man and perfect teacher.
Though still half way in the journey of following your tutorials, many fogs in my head for many years have been cleared. Thank you.
first time I run into tutorials like these, unique explanation, clear and calm voice well done man hope to see more like this
Steve, you are amazing. You talk slowly and calm and clear. Your voice has a very calm sound and makes me want to listen to you even if you describe how to vivisect a frog. Plus, your name just reminded me that it is many months I didn't check if there is any new Berserk chapter out.
Another great video, Steve! I'm watching almost all of your videos throught my learning journey with JS. If I need to understand better a specific concept, I hurry to your channel. Keep going, you're doing an amazing job! 🤗 💖
Thanks Steve! You make excellent tutorials that are very clear and easy to follow.
The fact that objects automatically update everywhere they are located is truly amazing!
this is due to pass by reference
Amazing! Thanks for your clear explanations.🌹
I know this is an older video but could you explain a bit more about why just adding the line dog["age"]=14 didn't work? Woody was declared up at the top so I expected to see that one updated. Thanks!
If you look at the object literal that was assigned to dog, on line 2, it did not have a property called "age".
@@SteveGriffith-Prof3ssorSt3v3 I can't believe I missed that. Thank you!
Thank you Steve I have learn a lot from your channel keep making videos .....cheers..
Superb❤️
Brilliant tutorials !!!
@6:14 So, would the age data for dog be added if we had used dog.age = 14; instead or would it throw an error because there are 2 dogs in the array?
If you do EITHER or BOTH of these:
dog.age = 14;
dog['age'] = 14;
Then you will add a property called age to the object dog, if it doesn't exist, or update its value, if it already exists.
5:39: Are you adding the label "age" to the variable "cat" or is "age" a variable within a variable? My take is that ir'd be the same as I writing "age":"2" on line 3
cat and dog are variables that hold objects. Both objects have "properties" called "age".
There are two ways to get or set the value of the property age.
1. Square bracket syntax with the property name in quotation marks. objectName["propertyName"]
2. dot notation - objectName.propertyName
The square bracket syntax is what you MUST use if you are using a variable to hold the name of the property.
totally amazed
amazing explanation, thanks.
Thank you a lot :)
How to add a similiar property for the several objects shortly?
That really depends on the context and what you are adding - a method, or a primitive value, or an array. What objects are you adding them to?
If you just have a couple objects and you want to add a property to each one...
let obj1 = { };
let obj2 = { };
let obj3 = { };
obj1.prop = 1;
obj2.prop = 1;
obj3.prop = 1;
You work with them each individually.
If you have a method that you want to add to a lot of objects then you should think about adding that to the prototype for your objects.
Thank you !
Is "var" from line 7 the only element that would differentiate an array from adding a new label to an object as in line 16? The latter looks very similar to an array nomenclature in terms of using square brackets.
To create an array, use [ ]
To create an object, use { }
arrays use numbers to access their values
objects use names / labels to access their values.
BOTH objects and arrays can use the square bracket syntax to target their contents.
Thank you very much,
How can I let more than 1 atribute to property?
Sorry. Don't understand your question.
property has a single word definition ex { name :"User"}, if you want the key to be of two words i.e. User name instead of name you can define like this
let user= {
"User name" : "Named user",
}; and access the property like this ----> console.log(user["User name"]); if i have understood your question correctly then this is what you were looking for
How can you add and isolate an object when adding it to an array, so if the elements in the array change, it doesn't change the original object? I tried putting the object in () like "pets=[cat, (dog)]" but that didn't isolate it.
You can't prevent any of the elements from being changed in the array. Any element in an array can be targeted and changed or replaced.
Further, if you changed the object cat or the object dog then the contents of the pets array would now be pointing to the updated version of the objects.
Thank YOu!!!
Wouldn't it have been the same to add "age":"14" to var dog from the beginning OR being added as dog.age=14?
Same thing. Just one is happening at the time where the object is being created and the other is happening after the object is created.
Hey Steve if I wanted to delete any of my objects properties I would use delete Operator right?
as is: delete cat.age;
And how can I save the value in a var before I deleted it? Is this correct? var deleted = delete cat['age'];
The delete operator is how you would remove a property from an Object (if allowed). However, the delete operator does NOT return the value of what it is deleting. It only returns true or false. You would have to put the value into a variable BEFORE calling delete.
var Obj = { };
Obj.myprop = 123;
var temp = Obj.myprop;
delete Obj.myprop;
Cool. Adding objects into an array. How about the opposite? 🙂
let obj = {
prop: [1, 2, 3, 4, 5]
}
@@SteveGriffith-Prof3ssorSt3v3 I'm either soing something strange, or seeing something strange.
arr= [1,2,3,4,5];
let obj ={};
obj = arr;
console.log(obj[arr[0]]);
2
console.log(obj);
[ 1, 2, 3, 4, 5 ]
Then wrote: console.log(obj[0]);
1
@@jaimedpcaus1 your third line you are overwriting the object with an array
@@SteveGriffith-Prof3ssorSt3v3 meaning it got converted from an object to an array?
You should add these codes on Github.
All the tutorials that I have done in the last two years have the code on Github.
second round, still amazing.
how are you doing now?
What would be the main difference between using CONSOLE.LOG and DOCUMENT.WRITE? I have come across different positions with regard to those two commands. On one side, DOCUMENT.WRITE not being recommended and on the other side CONSOLE.LOG being used merely as a tool for developers. Then I found RETURN... Here is a CodeAcademy answer, which makes a lot of sense: www.codecademy.com/en/forum_questions/53121d097c82ca0a33003906
document.write( ) is a way to add new content to the source of an html file WHILE THE HTML FILE IS LOADING. This is NOT recommended. Use the DOM methods to add new HTML to your page after the DOMContentLoaded event has occurred. Document.write( ) does NOTHING after the page has finished loading.
Console.log( ) is used to write messages to the console. This is for development use only.
Which would be a practical application of document.write? If it exists it has to have a usage within our developing work, I would image.
Cesar Juarez-Vargas 20 years ago it was used. No practical use anymore. Avoid it.
+++