0% found this document useful (0 votes)
7 views

Javascript Notes #1

Uploaded by

mauismallbiz
Copyright
© © All Rights Reserved
Available Formats
Download as TXT, PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
7 views

Javascript Notes #1

Uploaded by

mauismallbiz
Copyright
© © All Rights Reserved
Available Formats
Download as TXT, PDF, TXT or read online on Scribd
You are on page 1/ 1

# All About Variables

Variable Declarations

- To use variables in JS first we must create them


- this can be done by declaring a variable
- To declare variables we use one of these three keywords
- var
- The var statement declares a function-scoped or globally-scoped variable,
optionally intializing it to a value
- let
- The let declaration declares a block-scoped local variable, optionally
initializing it to a value
- const
- const or constants ar block-scoped much like variables declared using the
let keyword
- However the value of a constant cant be changed through reassingment and
cant be redeclared
- Importantly, if a const is declared to be an object or array, its
properties or items can be updated or removed

Hoisting

- JS Hoisting refers to the process in wich the interpreter apears to move the
declaration of functions variables or classes to the top of thier scope, prior to
execution of the code

Naming Rules

- When declaring variablels it is important to use clear names that are easy to
find or define
- propper variable naming can improve the readability of code

Scopes

- In JS scope refers to the visibility of a variable after it was declared


- the scope of a variable depends on the keywords used to declare it
- The three keywords were mentioned above, these are the scopes:
- Global Scope
- Variables declared outside any function or cuurly braces have a Global
Scope
- These variables can be accessed from anywhere within the same Javascript
code
- Function Scope
- Variables delcared within a function have a Function scope
- These variables can only be used within that same function
- Outside of that function, they are undefined
- Block Scope
- A block is any part of JS code bounded by curly braces
- variables declared within a block cannot be accessed outside that block
- This scope is only provided by the let and const keywords
- Local Scope
- Local variables are only recognized inside their respepctive functions
- variables with the same name can be used in different functions.
- Local variables are creates when a function starts, and is deleted when
the function is completed

You might also like