.github
api-server
client
config
curriculum
docs
guide
arabic
chinese
english
3d
accessibility
agile
algorithms
android-development
angular
apache
aspnet
bash
blender
blockchain
bootstrap
bsd-os
bulma
c
canvas
certifications
apis-and-microservices
coding-interview-prep
data-visualization
front-end-libraries
information-security-and-quality-assurance
javascript-algorithms-and-data-structures
basic-algorithm-scripting
basic-data-structures
basic-javascript
access-array-data-with-indexes
access-multi-dimensional-arrays-with-indexes
accessing-nested-arrays
accessing-nested-objects
accessing-object-properties-with-bracket-notation
accessing-object-properties-with-dot-notation
accessing-object-properties-with-variables
add-new-properties-to-a-javascript-object
add-two-numbers-with-javascript
adding-a-default-option-in-switch-statements
appending-variables-to-strings
assignment-with-a-returned-value
build-javascript-objects
chaining-if-else-statements
comment-your-javascript-code
comparison-with-the-equality-operator
comparison-with-the-greater-than-operator
comparison-with-the-greater-than-or-equal-to-operator
comparison-with-the-inequality-operator
comparison-with-the-less-than-operator
comparison-with-the-less-than-or-equal-to-operator
comparison-with-the-strict-equality-operator
comparison-with-the-strict-inequality-operator
comparisons-with-the-logical-and-operator
comparisons-with-the-logical-or-operator
compound-assignment-with-augmented-addition
compound-assignment-with-augmented-division
compound-assignment-with-augmented-multiplication
compound-assignment-with-augmented-subtraction
concatenating-strings-with-plus-operator
concatenating-strings-with-the-plus-equals-operator
constructing-strings-with-variables
count-backwards-with-a-for-loop
counting-cards
create-decimal-numbers-with-javascript
declare-javascript-variables
index.md
declare-string-variables
decrement-a-number-with-javascript
delete-properties-from-a-javascript-object
divide-one-decimal-by-another-with-javascript
divide-one-number-by-another-with-javascript
escape-sequences-in-strings
escaping-literal-quotes-in-strings
find-the-length-of-a-string
finding-a-remainder-in-javascript
generate-random-fractions-with-javascript
generate-random-whole-numbers-with-javascript
generate-random-whole-numbers-within-a-range
global-scope-and-functions
global-vs.-local-scope-in-functions
golf-code
increment-a-number-with-javascript
initializing-variables-with-the-assignment-operator
introducing-else-if-statements
introducing-else-statements
iterate-odd-numbers-with-a-for-loop
iterate-through-an-array-with-a-for-loop
iterate-with-javascript-do...while-loops
iterate-with-javascript-for-loops
iterate-with-javascript-while-loops
local-scope-and-functions
logical-order-in-if-else-statements
manipulate-arrays-with-pop
manipulate-arrays-with-push
manipulate-arrays-with-shift
manipulate-arrays-with-unshift
manipulating-complex-objects
modify-array-data-with-indexes
multiple-identical-options-in-switch-statements
multiply-two-decimals-with-javascript
multiply-two-numbers-with-javascript
nest-one-array-within-another-array
nesting-for-loops
passing-values-to-functions-with-arguments
practice-comparing-different-values
profile-lookup
quoting-strings-with-single-quotes
record-collection
replacing-if-else-chains-with-switch
return-a-value-from-a-function-with-return
return-early-pattern-for-functions
returning-boolean-values-from-functions
selecting-from-many-options-with-switch-statements
shopping-list
stand-in-line
store-multiple-values-in-one-variable-using-javascript-arrays
storing-values-with-the-assignment-operator
subtract-one-number-from-another-with-javascript
testing-objects-for-properties
understand-string-immutability
understanding-boolean-values
understanding-case-sensitivity-in-variables
understanding-undefined-value-returned-from-a-function
understanding-uninitialized-variables
updating-object-properties
use-bracket-notation-to-find-the-first-character-in-a-string
use-bracket-notation-to-find-the-last-character-in-a-string
use-bracket-notation-to-find-the-nth-character-in-a-string
use-bracket-notation-to-find-the-nth-to-last-character-in-a-string
use-conditional-logic-with-if-statements
use-multiple-conditional-ternary-operators
use-the-conditional-ternary-operator
use-the-parseint-function
use-the-parseint-function-with-a-radix
using-objects-for-lookups
word-blanks
write-reusable-javascript-with-functions
index.md
debugging
es6
functional-programming
intermediate-algorithm-scripting
javascript-algorithms-and-data-structures-projects
object-oriented-programming
regular-expressions
index.md
responsive-web-design
index.md
chef
clojure
cloud-development
codeigniter
computational-genomics
computer-hardware
computer-science
containers
cplusplus
csharp
css
d3
data-science-tools
dc
design-patterns
designer-tools
developer-ethics
developer-tools
devops
dns
docker
documentation
drupal
electron
elixir
elm
erlang
fsharp
game-development
gatsbyjs
git
gnupg
go
graphql
groovy
haskell
haxe
hibernate
html
ionic
java
javascript
joomla
jquery
julia
kotlin
laravel
linux
logic
machine-learning
mariadb
mathematics
meta
miscellaneous
mobile-app-development
mongodb
natural-language-processing
neovim
network-engineering
nginx
nodejs
optical-alignment
php
powershell
product-design
progressive-web-apps
puppet
python
r
raspberry-pi
react
react-native
redux
rest-api
robotics
rt-os
ruby
rust
sass
security
semantic-ui
software-engineering
sql
ssh
svg
svn
swift
tailwindcss
terminal-commandline
tomcat
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
tools
.editorconfig
.eslintignore
.eslintrc.json
.gitattributes
.gitignore
.node-inspectorrc
.prettierrc
.snyk
.travis.yml
.vcmrc
CODE_OF_CONDUCT.md
CONTRIBUTING.md
Dockerfile.tests
LICENSE.md
README.french.md
README.italian.md
README.md
azure-pipelines.yml
change_volumes_owner.sh
docker-compose-shared.yml
docker-compose.tests.yml
docker-compose.yml
lerna.json
libcimp_index_js.patch
package-lock.json
package.json
patch_npm_and_install.sh
sample.env
1.0 KiB
1.0 KiB
title
title |
---|
Declare JavaScript Variables |
Declare JavaScript Variables
When we store data in a data structure, we call it a variable. JavaScript variables are written in camel case. An example of camel case is: camelCase
.
You can declare a variable this way
var myName = "Rafael";
ES6 introduced two other ways to declare variables. let and const. Let is pretty similar to var and for the most part is interchangeable:
let myAge = 36;
Where let differs, is in its scope. When we declare using var, it's global in scope. When we declare using let, the scope is limited to that function. If you want to use a let variable outside a function, you have to make it global in scope or redeclare it in the next function.
const, on the other hand, can only be declared once. Its value can never change.
const myName = "Christina";