There are currently no frequently asked questions associated with this exercise – that’s where you come in! You can contribute to this section by offering your own questions, answers, or clarifications on this exercise. Ask or answer a question by clicking reply () below.
If you’ve had an “aha” moment about the concepts, formatting, syntax, or anything else with this exercise, consider sharing those insights! Teaching others and answering their questions is one of the best ways to learn and stay sharp.
Join the Discussion. Help a fellow learner on their journey.
Ask or answer a question about this exercise by clicking reply () below!
Agree with a comment or answer? Like () to up-vote the contribution!
In this snippet of code, faserShip is an object. It has 2 properties: 'Fuel Type' and color. Property names are similar to variable names. Similar, but not exactly like variable names. We can’t name a variable Fuel Type with or without quotes. In JavaScript the convention for a variable would be to name it fuelType. If we called our property fuelType it would not require quotes. Property names, unlike variable names, can have spaces in them as long as we wrap the property name in quotes: 'Fuel Type'. The short answer to your specific question is because the property name: color doesn’t contain any spaces quotes are not required. The values ('Turbo Fuel' & 'silver') of the properties require quotes because they are string literals.
Perhaps camelCase was not used in this example to showcase that a space is a special character and needs quotation marks. The example also shows you can have a space in a property name and that is how it is different from a variable name which doesn’t allow a space.
A general rule of thumb is to always declare your variables with the const keyword unless you’re certain that you’ll reassign it a value later on in your code
Something important to note is that even if you declare your variable with const, the object can be mutated meaning we can add properties to the object, delete properties from the object, and modify existing properties. The only thing constant is the bind between the variable and its value. So you can’t reassign a value to a constant variable
Even though I understand the syntax of objects, I don’t know what they actually are. Can someone please explain what objects are?
What I understood so far is that objects are used to group related data and functionality. Therefore, we can use objects to create models of real-life things - like a basketball. An object is made up of key-value pairs. Keys (also referred to as properties) are basically the different characteristics of the objects (the color, the size, etc.) and values are simply the values we assign to the property (“red”, “1cm”, etc.)
let spaceship = {
‘Fuel Type’: ‘diesel’,
color: ‘silver’
};
Do objects need its variable’s second word’s letter to be capitalized?
(i.e. can it be like this:
let spaceShip = {
‘Fuel Type’: ‘diesel’,
color: ‘silver’
}; )
In the introduction lesson 7 types are listed, but array is not in the list. How come? Isn’t array a data type? Or is it a special kind of an object? Please elaborate.