Object Oriented JavaScript Tutorial #3 - Updating Properties

Net Ninja · Beginner ·🔧 Backend Engineering ·8y ago

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
Sign in to unlock AI tutor explanation · ⚡30

Playlist

Uploads from Net Ninja · Net Ninja · 52 of 60

1 Regular Expressions (RegEx) Tutorial #14 - Matching a Username
Regular Expressions (RegEx) Tutorial #14 - Matching a Username
Net Ninja
2 Regular Expressions (RegEx) Tutorial #15 - Email RegEx Pattern
Regular Expressions (RegEx) Tutorial #15 - Email RegEx Pattern
Net Ninja
3 Regular Expressions (RegEx) Tutorial #16 - Finishing Touches
Regular Expressions (RegEx) Tutorial #16 - Finishing Touches
Net Ninja
4 GraphQL Tutorial #1 - Introduction to GraphQL
GraphQL Tutorial #1 - Introduction to GraphQL
Net Ninja
5 GraphQL Tutorial #2 - A Birdseye View of GraphQL
GraphQL Tutorial #2 - A Birdseye View of GraphQL
Net Ninja
6 GraphQL Tutorial #3 - Project (stack) Overview
GraphQL Tutorial #3 - Project (stack) Overview
Net Ninja
7 GraphQL Tutorial #4 - Making Queries (front-end preview)
GraphQL Tutorial #4 - Making Queries (front-end preview)
Net Ninja
8 GraphQL Tutorial #5 - Express App Setup
GraphQL Tutorial #5 - Express App Setup
Net Ninja
9 GraphQL Tutorial #6 - Setting up GraphQL
GraphQL Tutorial #6 - Setting up GraphQL
Net Ninja
10 GraphQL Tutorial #7 - GraphQL Schema
GraphQL Tutorial #7 - GraphQL Schema
Net Ninja
11 GraphQL Tutorial #8 - Root Query
GraphQL Tutorial #8 - Root Query
Net Ninja
12 GraphQL Tutorial #9 - The Resolve Function
GraphQL Tutorial #9 - The Resolve Function
Net Ninja
13 GraphQL Tutorial #10 - Testing Queries in Graphiql
GraphQL Tutorial #10 - Testing Queries in Graphiql
Net Ninja
14 GraphQL Tutorial #11 - GraphQL ID Type
GraphQL Tutorial #11 - GraphQL ID Type
Net Ninja
15 GraphQL Tutorial #12 - Author Type
GraphQL Tutorial #12 - Author Type
Net Ninja
16 GraphQL Tutorial #13 - Type Relations
GraphQL Tutorial #13 - Type Relations
Net Ninja
17 GraphQL Tutorial #14 - GraphQL Lists
GraphQL Tutorial #14 - GraphQL Lists
Net Ninja
18 GraphQL Tutorial #15 - More on Root Queries
GraphQL Tutorial #15 - More on Root Queries
Net Ninja
19 GraphQL Tutorial #16 - Connecting to mLab
GraphQL Tutorial #16 - Connecting to mLab
Net Ninja
20 GraphQL Tutorial #17 - Mongoose Models
GraphQL Tutorial #17 - Mongoose Models
Net Ninja
21 GraphQL Tutorial #18 - Mutations
GraphQL Tutorial #18 - Mutations
Net Ninja
22 GraphQL Tutorial #19 - More on Mutations
GraphQL Tutorial #19 - More on Mutations
Net Ninja
23 GraphQL Tutorial #20 - Updating the Resolve Functions
GraphQL Tutorial #20 - Updating the Resolve Functions
Net Ninja
24 GraphQL Tutorial #21 - GraphQL NonNull
GraphQL Tutorial #21 - GraphQL NonNull
Net Ninja
25 GraphQL Tutorial #22 - Adding a Front-end
GraphQL Tutorial #22 - Adding a Front-end
Net Ninja
26 GraphQL Tutorial #23 - Create React App
GraphQL Tutorial #23 - Create React App
Net Ninja
27 GraphQL Tutorial #24 - Book List Component
GraphQL Tutorial #24 - Book List Component
Net Ninja
28 GraphQL Tutorial #25 - Apollo Client Setup
GraphQL Tutorial #25 - Apollo Client Setup
Net Ninja
29 GraphQL Tutorial #26 - Making Queries from React
GraphQL Tutorial #26 - Making Queries from React
Net Ninja
30 GraphQL Tutorial #27 - Rendering Data in a Component
GraphQL Tutorial #27 - Rendering Data in a Component
Net Ninja
31 GraphQL Tutorial #28 - Add Book Component
GraphQL Tutorial #28 - Add Book Component
Net Ninja
32 GraphQL Tutorial #29 - External Query File
GraphQL Tutorial #29 - External Query File
Net Ninja
33 GraphQL Tutorial #30 - Updating Component State
GraphQL Tutorial #30 - Updating Component State
Net Ninja
34 GraphQL Tutorial #31 - Composing Queries
GraphQL Tutorial #31 - Composing Queries
Net Ninja
35 GraphQL Tutorial #32 - query variables
GraphQL Tutorial #32 - query variables
Net Ninja
36 GraphQL Tutorial #33 - Re-fetching Queries
GraphQL Tutorial #33 - Re-fetching Queries
Net Ninja
37 GraphQL Tutorial #34 - Book Details Component
GraphQL Tutorial #34 - Book Details Component
Net Ninja
38 GraphQL Tutorial #36 - Styling the App
GraphQL Tutorial #36 - Styling the App
Net Ninja
39 GraphQL Tutorial #35 - Making a Single Query
GraphQL Tutorial #35 - Making a Single Query
Net Ninja
40 Build Apps with Vue & Firebase - Udemy Course
Build Apps with Vue & Firebase - Udemy Course
Net Ninja
41 Updated Vue & Firebase Course (Udemy)
Updated Vue & Firebase Course (Udemy)
Net Ninja
42 Vue & Firebase Real-time Chat (Preview) #1 - Intro
Vue & Firebase Real-time Chat (Preview) #1 - Intro
Net Ninja
43 Vue & Firebase Real-time Chat (Preview) #2 - Project Structure
Vue & Firebase Real-time Chat (Preview) #2 - Project Structure
Net Ninja
44 Vue & Firebase Real-time Chat (Preview) #3 - Firestore Setup
Vue & Firebase Real-time Chat (Preview) #3 - Firestore Setup
Net Ninja
45 Vue & Firebase Real-time Chat (Preview) #4 - Welcome Screen
Vue & Firebase Real-time Chat (Preview) #4 - Welcome Screen
Net Ninja
46 Vue & Firebase Real-time Chat (Preview) #5 - Props in Routes
Vue & Firebase Real-time Chat (Preview) #5 - Props in Routes
Net Ninja
47 Vue & Firebase Real-time Chat (Preview) #6 - Route Guards
Vue & Firebase Real-time Chat (Preview) #6 - Route Guards
Net Ninja
48 Vue & Firebase Real-time Chat (Preview) #7 - Chat Window
Vue & Firebase Real-time Chat (Preview) #7 - Chat Window
Net Ninja
49 Vue & Firebase Real-time Chat (Preview) #8 - New Message Component
Vue & Firebase Real-time Chat (Preview) #8 - New Message Component
Net Ninja
50 Object Oriented JavaScript Tutorial #1 - Introduction
Object Oriented JavaScript Tutorial #1 - Introduction
Net Ninja
51 Object Oriented JavaScript Tutorial #2 - Object Literals
Object Oriented JavaScript Tutorial #2 - Object Literals
Net Ninja
Object Oriented JavaScript Tutorial #3 - Updating Properties
Object Oriented JavaScript Tutorial #3 - Updating Properties
Net Ninja
53 Object Oriented JavaScript Tutorial #4 - Classes
Object Oriented JavaScript Tutorial #4 - Classes
Net Ninja
54 Object Oriented JavaScript Tutorial #5  - Class Constructors
Object Oriented JavaScript Tutorial #5 - Class Constructors
Net Ninja
55 Object Oriented JavaScript Tutorial #6 - Class Methods
Object Oriented JavaScript Tutorial #6 - Class Methods
Net Ninja
56 Object Oriented JavaScript Tutorial #7 - Method Chaining
Object Oriented JavaScript Tutorial #7 - Method Chaining
Net Ninja
57 Object Oriented JavaScript Tutorial #8 - Class Inheritance
Object Oriented JavaScript Tutorial #8 - Class Inheritance
Net Ninja
58 Object Oriented JavaScript Tutorial #9 - Constructors (under the hood)
Object Oriented JavaScript Tutorial #9 - Constructors (under the hood)
Net Ninja
59 Object Oriented JavaScript Tutorial #10 - Prototype
Object Oriented JavaScript Tutorial #10 - Prototype
Net Ninja
60 Object Oriented JavaScript Tutorial #11 - Prototype Inheritance
Object Oriented JavaScript Tutorial #11 - Prototype Inheritance
Net Ninja

This tutorial teaches how to update and create properties in Object Oriented JavaScript, and introduces ES6 classes for creating multiple objects of the same type. It covers the basics of dot notation, square brackets, and code organization.

Key Takeaways
  1. Create an object with properties and methods
  2. Update properties using dot notation
  3. Update properties using square brackets
  4. Create new properties and methods on existing objects
  5. Introduce ES6 classes for creating multiple objects of the same type
💡 Using ES6 classes can help create multiple objects of the same type without rewriting the object definition multiple times.

Related Reads

📰
When “Global” Isn’t Global: The Hidden Failure Mode of In-Memory State in FastAPI
Learn how in-memory state in FastAPI can lead to hidden failures in rate limiters, even when they seem to work in development
Medium · Python
📰
The Cost of Cleverness: A Backend Engineer’s Guide to Strategic Simplicity
Learn to balance code cleverness with simplicity and maintainability as a backend engineer
Dev.to · Edgar Nahama Alochi
📰
Designing Better Backend Systems for Data That Cannot Be Lost
Learn to design robust backend systems for critical data that cannot be lost, ensuring data integrity and reliability
Dev.to · Marc Keebler
📰
DNS Record Deletion in Node.js: List Identity Before Delete
Learn how to delete a DNS record in Node.js by first listing the zone and matching the record by name
Dev.to · QuintonShaw1483
Up next
Unlock CRAZY Performance: Native Code Compilation No JNI! #shorts #quarkusinsights #projectpanama
Quarkusio
Watch →