DEV Community

Cover image for That object over there looks interesting
MarceloVarela22377
MarceloVarela22377

Posted on

That object over there looks interesting

Controller Gang says "Hello" and Welcome

Hello, my name is Marcelo Varela and I am here to guide you on your journey to becoming a coding Master. In my last blog we talked about functions and methods, and today will be talking about ...

Objects!!

Ok, so what are objects? Objects are: a phone, a desk, a shoe. These are all objects and they each have properties and things they can do. Take the phone for Example:

/*
 ______________
 /              \ 
 |  Im A phone  | It has properties of:         Along with things it can do:
 |              | * colors                    * ring
 |              | * size                      * take a picture
 |              | * model                     * play music
 |              |
 |              |
 \ ____________ /
 */
Enter fullscreen mode Exit fullscreen mode

Phones are great examples of objects because of these traits they have. But how do we show objects and all the stuff that goes with them? So how do Objects work in JavaScript you may ask? Well let me show you.

First off we have two different types of objects: Object Literals and Math Objects.

Object Literals

Objects in general are made up of variables that have attributes for example.

let controllers = {
  consoleLinkedTo: 'XboxOneX',
  controllerColor: 'Ocean Blue',
  controllerTypes: 'elite', 'regular',
}
Enter fullscreen mode Exit fullscreen mode

Then log to the console using the command:

console.log(controllers);
Enter fullscreen mode Exit fullscreen mode

if you wish to log certain attributes of an object, you need to use: .(attribute) command shown here:

console.log(controller.consoleLinkedTo)
Enter fullscreen mode Exit fullscreen mode

Alt Text

The above piece of code is an example of a literal object and their calling to the console.

We can also add methods or internal functions to the attributes inside the objects shown here:

let controllers = {
  consoleLinkedTo: 'XboxOneX',
  controllerColors: 'Ocean Blue','armyGreen','White', 'Black'
  controllerTypes: 'elite', 'regular',
  rightTriggerTap: function (){
    console.log('controller user has tapped right trigger button and fired their weapon');
  },
  leftTriggerTap: function (){
    console.log(`controller user has tapped left trigger button and used their weapons scope`);
  },
}
Enter fullscreen mode Exit fullscreen mode

Math Objects

Math objects are internally defined commands that can be used to implement mathematical properties into code. Some types of Math objects include:

const areaOfController = 6.7in;

console.log(Math.round(radius);
Enter fullscreen mode Exit fullscreen mode

Other Math commands include the implementations of .PI and the numerical value .E using:

console.log(Math.PI);
console.log(Math.E);
Enter fullscreen mode Exit fullscreen mode

Another fun tool ia the .random tag which will grab a random whole number from whatever your boundary number is shown here:

console.log(Math.random * 500))
Enter fullscreen mode Exit fullscreen mode

Too many enemies, need to regroup!!

Let me review what we went over in today's blog:

  • first we learned what an object is,
  • second we learned the two types of objects(literal objects and Math Objects
  • We also learned how to implement internal functions and methods into our code.
  • Finally after writing the code we leaned to call them using console.log

Thanks for Reading, controller gang thanks you!

I hope you learned something from this blog and I hope you have a great rest of your day or night. If you ever need help with anything else, don't shy away from shooting me a message down in the comments below.

References

Udemy-

https://www.udemy.com

VSCode-

https://code.visualstudio.com

IronHack Info Doc.-

https://docs.google.com/document/d/1AOAFfkGFjcpUicEB-5pXbGsl53Nib8YoZDCA--A1z8o/edit?

Dev.to
https://dev.to

Oldest comments (0)