Basic Javascript (81/111) | Build JavaScript Objects | freeCodeCamp
Full playlist 👉 • Basic JavaScript (1/111) | Comment Yo...
You may have heard the term object before.
Objects are similar to arrays, except that instead of using indexes to access and modify their data, you access the data in objects through what are called properties.
Objects are useful for storing data in a structured way, and can represent real world objects, like a cat.
Here's a sample cat object:
var cat = {
""name"": ""Whiskers"",
""legs"": 4,
""tails"": 1,
""enemies"": [""Water"", ""Dogs""]
};
In this example, all the properties are stored as strings, such as - ""name"", ""legs"", and ""tails"". However, you can also use numbers as properties. You can even omit the quotes for single-word string properties, as follows:
var anotherObject = {
make: ""Ford"",
5: ""five"",
""model"": ""focus""
};
However, if your object has any non-string properties, JavaScript will automatically typecast them as strings.
Make an object that represents a dog called myDog which contains the properties ""name"" (a string), ""legs"", ""tails"" and ""friends"".
You can set these object properties to whatever values you want, as long as ""name"" is a string, ""legs"" and ""tails"" are numbers, and ""friends"" is an array."
Watch video Basic Javascript (81/111) | Build JavaScript Objects | freeCodeCamp online, duration hours minute second in high quality that is uploaded to the channel Stral Tech 07 November 2020. Share the link to the video on social media so that your subscribers and friends will also watch this video. This video clip has been viewed 262 times and liked it 6 visitors.