Update article.md

This commit is contained in:
Khai Nguyen 2018-10-22 16:21:43 -07:00 committed by GitHub
parent dc904d122e
commit 547aead304
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23

View file

@ -1,19 +1,22 @@
# Methods of primitives
JavaScript allows us to work with primitives (strings, numbers etc) as if they were objects.
JavaScript allows us to work with primitives (strings, numbers, etc.) as if they were objects.
They also provide methods to call as such. We will study those soon, but first we'll see how it works, because, of course, primitives are not objects (and here we will make it even more clear).
They also provide methods to call as such. We will study those soon, but first we'll see how it works because, of course, primitives are not objects (and here we will make it even clearer).
Let's look at the key distinction between primitives and objects.
Let's look at the key distinctions between primitives and objects.
A primitive
: Is a value of a primitive type. There are 6 primitive types: `string`, `number`, `boolean`, `symbol`, `null` and `undefined`.
- Is a value of a primitive type.
- There are 6 primitive types: `string`, `number`, `boolean`, `symbol`, `null` and `undefined`.
An object
: Is capable of storing multiple values as properties.
Can be created with `{}`, for instance: `{name: "John", age: 30}`. There are other kinds of objects in JavaScript, e.g. functions are objects.
One of the best things about objects is that we can store a function as one of its properties:
- Is capable of storing multiple values as properties.
- Can be created with `{}`, for instance: `{name: "John", age: 30}`. There are other kinds of objects in JavaScript; functions, for example, are objects.
One of the best things about objects is that we can store a function as one of its properties.
```js run
let john = {
@ -28,7 +31,7 @@ john.sayHi(); // Hi buddy!
So here we've made an object `john` with the method `sayHi`.
Many built-in objects already exist, such as those that work with dates, errors, HTML elements etc. They have different properties and methods.
Many built-in objects already exist, such as those that work with dates, errors, HTML elements, etc. They have different properties and methods.
But, these features come with a cost!