Files
.github
api-server
client
config
curriculum
docs
guide
arabic
chinese
english
3d
accessibility
agile
algorithms
android-development
angular
angularjs
apache
aspnet
bash
blockchain
book-recommendations
bootstrap
bsd-os
bulma
c
canvas
certifications
chef
clojure
cloud-development
computational-genomics
computer-hardware
computer-science
containers
cplusplus
csharp
css
d3
data-science-tools
design-patterns
designer-tools
developer-ethics
developer-tools
devops
docker
documentation
electron
elixir
elm
erlang
fsharp
game-development
gatsbyjs
git
go
groovy
haskell
hibernate
html
ionic
java
javascript
additional-javascript-resources
advantages-and-disadvantages-of-javascript
angularjs-interview-questions
arguments
arithmetic-operation
arrow-functions
assignment-operators
async-messaging-with-rabbitmq-tortoise
await-promises
booleans
callback-functions
classes
closures
code-blocks
code-linting-in-javascript
comments
comparison-operators
concurrency-model-and-event-loop
conditional-ternary-operators
converting-strings-to-numbers
error-handling-and-try-catch-throw
es6
falsy-values
form-validation
function-composition
function-invocation
functions-list
get-timestamp
global-object
global-variables
higher-order-functions
html-dom
html-dom-getelementbyid-method
html-dom-innerhtml-property
html-dom-queryselector
if-else-statement
immediately-invoked-functions-expressions
immutable-types
location-object
location-reload-method
logical-operators
loops
manipulate-javascript-objects
manipulating-cookies
multiply-two-numbers-with-javascript
naming-convention-for-javascript
numbers
object-instantiation
onclick-event
onload-event
output
popup-boxes
promises
prototypes
random-method
regular-expressions-reference
rest-parameters
return-statements
scopes
semicolons
singleton-in-javascript
spread-syntax
standard-objects
strict-mode
switch-statements
template-literals
ternary-operator
this-reference
timing-events
truth-table
truthy-values
tutorials
add-new-properties-to-a-javascript-object
add-two-numbers-with-javascript
build-javascript-objects
index.md
comment-your-javascript-code
construct-javascript-objects-with-functions
create-a-javascript-slot-machine
create-decimal-numbers-with-javascript
debugging-javascript-with-browser-devtools
debugging-node-files-using-cli-commands
declare-javascript-objects-as-variables
declare-javascript-variables
decrement-a-number-with-javascript
delete-properties-from-a-javascript-object
detect-authentic-click-events
divide-one-number-by-another-with-javascript
finding-a-remainder-in-javascript
generate-random-fractions-with-javascript
generate-random-whole-numbers-with-javascript
get-current-url-in-javascript
give-your-javascript-slot-machine-some-stylish-images
how-to-create-a-countdown-timer
how-to-create-a-dropdown-menu-with-css-and-javascript
how-to-create-a-lightbox
how-to-create-a-slideshow
how-to-create-a-top-navigation-bar
how-to-create-an-accordion
how-to-create-popups
how-to-create-tabs
how-to-install-node-js-and-npm-on-windows
increment-a-number-with-javascript
invert-regular-expression-matches-with-javascript
iterate-with-javascript-for-loops
iterate-with-javascript-while-loops
javascript-for-loops-explained
page-redirects-using-javascript
perform-arithmetic-operations-on-decimals-with-javascript
store-multiple-values-in-one-variable-using-javascript-arrays
subtract-one-number-from-another-with-javascript
the-javascript-version-of-jquerygetjson
use-the-javascript-console
using-anonymous-functions-for-private-namespacing-in-your-javascript-apps
what-does-javascript-void-0-mean
write-reusable-javascript-with-functions
index.md
typeof
undefined-primitive-values
where-to
window-clearinterval-method
window-cleartimeout-method
window-confirm-method
window-localstorage
window-location
window-open-method
window-setinterval-method
window-settimeout-method
with
index.md
joomla
jquery
julia
kotlin
laravel
linux
logic
machine-learning
mathematics
meta
miscellaneous
mobile-app-development
mongodb
natural-language-processing
neovim
network-engineering
nginx
nodejs
php
product-design
progressive-web-apps
puppet
python
r
react
react-native
redux
rest-api
robotics
rt-os
ruby
rust
sass
security
semantic-ui
software-engineering
sql
ssh
svg
svn
swift
terminal-commandline
tools
typescript
typography
user-experience-design
user-experience-research
vagrant
vim
virtualbox
visual-design
voice
vue
vue-cli
web-augmented-reality
web-components
web-performance
web-virtual-reality
wordpress
working-in-tech
xml
portuguese
russian
spanish
mock-guide
news
tools
.editorconfig
.eslintignore
.eslintrc
.gitattributes
.gitignore
.node-inspectorrc
.prettierrc
.snyk
.travis.yml
.vcmrc
CODE_OF_CONDUCT.md
CONTRIBUTING.md
LICENSE.md
README.md
docker-compose-shared.yml
docker-compose.yml
lerna.json
netlify.toml
package-lock.json
package.json
sample.env
2018-10-16 21:32:40 +05:30

1.0 KiB

title
title
Build JavaScript Objects

Objects are useful for storing data in a structured way, and can be used to represent real world objects, like a cars or hotel to a computer.

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. There are two ways main to create objects: the Object Literal and the Constructor way.

Using the Object Literal way, here's how we would create sample object:

var cat = {
    name: "Whiskers",
    legs: 4,
    tails: 1,
    enemies: ["Water", "Dogs"]
 };

Using the Constructor way, here's how we would create sample object:

var cat = new Object();
cat.name = "Whiskers";
cat.legs = 4;
cat.tails = 1;
cat.enemies = ["Water", "Dogs"];

In the Constructor way, we use the new keyword together with Object (with capital 'O') to create a new object instance. Afterward, we use dot notation to assign the property names and values of the object.