Fireship · @fireship
An Encounter with JavaScript Objects
Uploaded October 18, 2019 · Length 10:38
Summary
This video teaches how to work with JavaScript objects, including creating them, setting properties, and using modern syntax and methods to make code cleaner and more efficient.
- javascript objects
- object literal syntax
- constructor syntax
- object create
- defined property
- object destructuring
- object methods
- this keyword
- object references
Transcript preview
The first 2 minutes of the transcript. Select a timestamp to watch that moment on YouTube.
- 0:00
[Music]
- 0:01
you unlock this door with the key of
- 0:04
imagination this is an object a
- 0:06
collection of properties where each
- 0:08
property associate say key to a value
- 0:10
earlier in the course we learned that
- 0:12
there are seven primitive data types in
- 0:13
Java Script primitives represent a
- 0:15
single value like a number or a string
- 0:17
and anything that's not a primitive is
- 0:19
an object in other words everything
- 0:21
interesting that happens in JavaScript
- 0:22
is made possible by the object datatype
- 0:28
today we'll take a deep dive into how
- 0:30
the JavaScript object works and look at
- 0:32
modern syntax and methods we can use to
- 0:34
make our code cleaner and more efficient
- 0:35
if you're new here like and subscribe
- 0:37
and grab all of the videos on this free
- 0:39
JavaScript course from bioship io an
- 0:41
object is conceptually similar to a
- 0:43
dictionary or a map that you might find
- 0:45
in other programming languages the most
- 0:47
straightforward way to create an object
- 0:48
is to use the literal syntax simply
- 0:51
define a variable equal to curly braces
- 0:53
inside the braces you define properties
- 0:56
separated by commas a property is
- 0:59
essentially a key value pair where the
- 1:00
left side is the property name and the
- 1:02
right side is the property value the
- 1:05
property name needs to be a unique value
- 1:07
that can be coerced to a string the
- 1:09
value can be anything you want a
- 1:10
primitive another object a function or
- 1:13
whatever now even though we define this
- 1:15
object as a const variable we can still
- 1:17
set properties on it after it's been
- 1:19
created we can use bracket notation on
- 1:21
the object followed by the name of the
- 1:23
property equal to whatever value we want
- 1:25
to set there then later in the code we
- 1:27
can read or get that property using the
- 1:29
same bracket notation
- 1:32
now let's imagine that we've walked into
- 1:34
an alternate universe because in
- 1:36
JavaScript there is always more than one
- 1:37
way to do things
- 1:38
this time we'll create a new object
- 1:40
using the constructor syntax then we'll
- 1:42
set properties on it using dot notation
- 1:44
dot notation looks a lot cleaner but
- 1:46
your property names will need to be a
- 1:48
continuous string that does not start
- 1:50
with a number if you have property names
- 1:51
with spaces or that start with numbers
- 1:53
you'll get a syntax error if you try to
- 1:55
call them with dot notation but now
- 1:58
we've fallen into yet another alternate


