Object Oriented JavaScript Tutorial #3 - Updating Properties
Key Takeaways
This video tutorial demonstrates how to update properties and create new ones in Object Oriented JavaScript, using dot notation and square brackets, and introduces the concept of classes in ES6 for creating multiple objects of the same type.
Full Transcript
or rather than so we have this object now encapsulating everything it means to be this user in one single place and that is a good good first step and we can access these properties right here and these methods by dot notation we saw that in the last video I could say use a1 which is the variable name here the object itself dot name and that is going to access this property right here so we can use this dot notation user 1 name user 1 email user 1 dot log in but say for instance I wanted to update one of these properties and a certain time in my code how do I do that well it's pretty simple we can just say user one name and then set that equal to something else so I could change the name from Rio to a Yoshi or something like that so if I save this now and then call over here user 1 oops have to spell it right user 1 then this will show me the object and the name is now Yoshi because down here we changed the name but if I change it back and I can do that in the console as well use a 1 dot name is now equal to a ryu again then this should update so if i call you to 1 again to see that object we can see the name property is now right all right now we can access properties in other ways we don't just have to use dot notation we can use square brackets as well so say for example I want to access the email property using dot notation and say user 1 dots email right not getting me but I can also use square brackets I can say user 1 and then in square brackets inside a string the email property right and it's important you put this in a string you can't just say email like that it needs to be a string and that it's going to go out and it's going to do the same thing as this it's going to give me the email property of this object so if a press enter we can see that now cool so that works as well and of course we can also update properties this way I could say user 1 and then in brackets the name like so and set that equal to Mario and this time if I call user one we should see that updated name so we can also use square brackets as well as this dot notation but you might be thinking well why what purpose does this serve well this way of accessing the property is useful when what we're accessing is dynamic and not necessarily set in stone for example let me just clear the console here and let's just create a variable called prop and this is going to be equal to a string called name so this property right here this variable may update at some point it might be email at some point now what we could do is say user one and then just pass in the prop to find out so what it's doing is passing this string right here into this square bracket and it's finding the main property now if later on prop became email then using user one prop like so would get the email so this thing that we're passing in could be dynamic and it could be chosen by the user some way shape or form and then when we try to access it it's going to do it we can't do that by saying user 1 dot prop because that doesn't exist we're looking for here a property on the user called prop and it doesn't exist right here we're passing in a variable so that's why this can be useful sometimes but most of the time you'll probably find yourself using dot notation to grab the properties like so now as well as accessing the different properties and methods on an object we can also create new properties on methods on that object as well for example I could say use a 1 dot age which doesn't exist yet and I could set that equal to 25 and that it's going to create an age property on that user so now if I type out user 1 like so we can see this age property now at the end so I could easily say user 1 age to grab that age property and I could do the same thing for methods as well I could say user 1 dot log info is equal to some kind of function and then inside here we could log something to the console so this is how we add on properties and methods to objects that already exist as well now I'm not a big fan of this I think if an object has a property or method it should be kept inside the object literal definition right here so that we can see everything in one place in my eyes if at some point in my program a user is gonna have an age property I should put that age property in to begin with even if I don't know the value of it I could just set it as null or zero to begin with and then update it later on I don't necessarily like adding on extra properties later but sometimes you may have to and you understand that that's not everyone's of you that's just my view so you can't do it if you want to so this is how we can create objects now have a give access to different properties and methods on them but there's one flaw imagine we have several users here right so we have user 1 user to user 3 etc and they all have these different values for the properties so how would we combat this well yeah what we could do is copy this and paste it down below and say you know user 2 is Yoshi etc and then we could do another one for user 3 like so but this is getting a bit out of control now because what we're doing is we're writing the property names and the functions over and over again for each different object now I want to show you a way we can easily create multiple objects of the same type because they're all a user right all the same type of object they just have different values inside I want to show you how we can easily create multiple instances of this kind of user object without having to rewrite the objects over and over again I'm going to show you that by using a new feature in es6 called classes
Original Description
Hey ninjas, in this Object Oriented JavaScript tutorial, we'll take a look at how we can update our object properties, as well as create new ones on the fly.
🐱💻 Course Links:
- VS Code editor - https://code.visualstudio.com/
- GitHub repository (course files) - https://github.com/iamshaunjp/object-oriented-js
- JavaScript for Beginners - https://www.youtube.com/watch?v=qoSksQ4s_hg&list=PL4cUxeGkcC9i9Ae2D9Ee1RvylH38dKuET
🤑 Donate @ https://www.paypal.me/thenetninja
🎓Find me on Udemy @ https://www.udemy.com/user/47fd83f6-5e4a-4e87-a0f0-519ac51f91b6/
👾 Video thumbnail artwork by PixelSwish @ https://www.youtube.com/channel/UCGKSD3mitWl5UpMxZzaIrRA
Playlist
Uploads from Net Ninja · Net Ninja · 52 of 60
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
▶
53
54
55
56
57
58
59
60
Regular Expressions (RegEx) Tutorial #14 - Matching a Username
Net Ninja
Regular Expressions (RegEx) Tutorial #15 - Email RegEx Pattern
Net Ninja
Regular Expressions (RegEx) Tutorial #16 - Finishing Touches
Net Ninja
GraphQL Tutorial #1 - Introduction to GraphQL
Net Ninja
GraphQL Tutorial #2 - A Birdseye View of GraphQL
Net Ninja
GraphQL Tutorial #3 - Project (stack) Overview
Net Ninja
GraphQL Tutorial #4 - Making Queries (front-end preview)
Net Ninja
GraphQL Tutorial #5 - Express App Setup
Net Ninja
GraphQL Tutorial #6 - Setting up GraphQL
Net Ninja
GraphQL Tutorial #7 - GraphQL Schema
Net Ninja
GraphQL Tutorial #8 - Root Query
Net Ninja
GraphQL Tutorial #9 - The Resolve Function
Net Ninja
GraphQL Tutorial #10 - Testing Queries in Graphiql
Net Ninja
GraphQL Tutorial #11 - GraphQL ID Type
Net Ninja
GraphQL Tutorial #12 - Author Type
Net Ninja
GraphQL Tutorial #13 - Type Relations
Net Ninja
GraphQL Tutorial #14 - GraphQL Lists
Net Ninja
GraphQL Tutorial #15 - More on Root Queries
Net Ninja
GraphQL Tutorial #16 - Connecting to mLab
Net Ninja
GraphQL Tutorial #17 - Mongoose Models
Net Ninja
GraphQL Tutorial #18 - Mutations
Net Ninja
GraphQL Tutorial #19 - More on Mutations
Net Ninja
GraphQL Tutorial #20 - Updating the Resolve Functions
Net Ninja
GraphQL Tutorial #21 - GraphQL NonNull
Net Ninja
GraphQL Tutorial #22 - Adding a Front-end
Net Ninja
GraphQL Tutorial #23 - Create React App
Net Ninja
GraphQL Tutorial #24 - Book List Component
Net Ninja
GraphQL Tutorial #25 - Apollo Client Setup
Net Ninja
GraphQL Tutorial #26 - Making Queries from React
Net Ninja
GraphQL Tutorial #27 - Rendering Data in a Component
Net Ninja
GraphQL Tutorial #28 - Add Book Component
Net Ninja
GraphQL Tutorial #29 - External Query File
Net Ninja
GraphQL Tutorial #30 - Updating Component State
Net Ninja
GraphQL Tutorial #31 - Composing Queries
Net Ninja
GraphQL Tutorial #32 - query variables
Net Ninja
GraphQL Tutorial #33 - Re-fetching Queries
Net Ninja
GraphQL Tutorial #34 - Book Details Component
Net Ninja
GraphQL Tutorial #36 - Styling the App
Net Ninja
GraphQL Tutorial #35 - Making a Single Query
Net Ninja
Build Apps with Vue & Firebase - Udemy Course
Net Ninja
Updated Vue & Firebase Course (Udemy)
Net Ninja
Vue & Firebase Real-time Chat (Preview) #1 - Intro
Net Ninja
Vue & Firebase Real-time Chat (Preview) #2 - Project Structure
Net Ninja
Vue & Firebase Real-time Chat (Preview) #3 - Firestore Setup
Net Ninja
Vue & Firebase Real-time Chat (Preview) #4 - Welcome Screen
Net Ninja
Vue & Firebase Real-time Chat (Preview) #5 - Props in Routes
Net Ninja
Vue & Firebase Real-time Chat (Preview) #6 - Route Guards
Net Ninja
Vue & Firebase Real-time Chat (Preview) #7 - Chat Window
Net Ninja
Vue & Firebase Real-time Chat (Preview) #8 - New Message Component
Net Ninja
Object Oriented JavaScript Tutorial #1 - Introduction
Net Ninja
Object Oriented JavaScript Tutorial #2 - Object Literals
Net Ninja
Object Oriented JavaScript Tutorial #3 - Updating Properties
Net Ninja
Object Oriented JavaScript Tutorial #4 - Classes
Net Ninja
Object Oriented JavaScript Tutorial #5 - Class Constructors
Net Ninja
Object Oriented JavaScript Tutorial #6 - Class Methods
Net Ninja
Object Oriented JavaScript Tutorial #7 - Method Chaining
Net Ninja
Object Oriented JavaScript Tutorial #8 - Class Inheritance
Net Ninja
Object Oriented JavaScript Tutorial #9 - Constructors (under the hood)
Net Ninja
Object Oriented JavaScript Tutorial #10 - Prototype
Net Ninja
Object Oriented JavaScript Tutorial #11 - Prototype Inheritance
Net Ninja
Related Reads
📰
📰
📰
📰
When “Global” Isn’t Global: The Hidden Failure Mode of In-Memory State in FastAPI
Medium · Python
The Cost of Cleverness: A Backend Engineer’s Guide to Strategic Simplicity
Dev.to · Edgar Nahama Alochi
Designing Better Backend Systems for Data That Cannot Be Lost
Dev.to · Marc Keebler
DNS Record Deletion in Node.js: List Identity Before Delete
Dev.to · QuintonShaw1483
🎓
Tutor Explanation
DeepCamp AI