Image courtesy of Pexels.com
Day Two in my one year quest to develop my coding skills. Every day during this challenge I will post at least one line of code that I've learned or worked on. I've been working through the free Codecademy course Introduction to JavaScript. Today I am exploring JavaScript Objects.
#CodingPhase #TheCodingWay #365CodingPhaseChallenge
My first task was to define a new object called fasterShip with two properties. This is the code I came up with:
let fasterShip = { 'Fuel Type': 'Turbo Fuel', color: 'silver' };
Next I was presented with the following code which defines an object with five properties:
let spaceship = {
homePlanet: 'Earth',
color: 'silver',
'Fuel Type': 'Turbo Fuel',
numCrew: 5,
flightPath: ['Venus', 'Mars', 'Saturn']
};
The lesson had me assign the value of a property containing a number to a variable. This is the successful code I came up with:
const crewCount = spaceship.numCrew;
I was next asked to try assigning an array of strings to a variable. I accomplished this in the same way. My code was:
const planetArray = spaceship.flightPath;
I also learned how to access the value of a property within an object using square brackets. The following code is one example I wrote to access the color of the spaceship from the object definition above and assign it to a variable:
const whatColor = spaceship['color'];
I also learned that an object defined using const cannot be reassigned but it can be mutated (i.e. modified) to add, change or remove property values.
Also, if you assign a function as a value to a property within an object, that property is considered to be a method and can be utilized as such.
This is just a bit of what I learned today. If I documented all of it, I would never get through the lessons! Have a great day coding and I'll see you here again tomorrow. :)
If you enjoyed this record of my experience learning to code and want to follow along going forward, please consider adding me on Twitter and following my blog here on Steemit:
https://steemit.com/@jeremycrow
My Website: JeremyCrow.com
Minds: Minds.com/JeremyCrow
Twitter: Twitter.com/JeremyCrow
Patreon: Patreon.com/jeremycrow
Instagram: Instagram.com/jeremycrow
YouTube: YouTube.com/user/ZigguratOfEnki
BitChute: BitChute.com/JeremyCrow (sign up here)