Here’s a few things to know when getting started with Javascript
Variables
Variables are used to store data, like the price of a item
let
and const
are used to declare variables
Variables declared with const
can not be updated later in your code, variables declared with let
can be updated throughout your code.
Use const
to store data you don’t expect to change, like your first name
Console Log
console.log
is used to view data in the terminal. console.log
will be your best friend when you run into bugs. You will have the ability to log variables into the terminal to see where the error is coming from
What type of data can be stored in a variable?
JavaScript has 7 primitive data types & 1 non primitive data type
String
- A sequence of text wrapped around double quotes: "", single quotes: '', or backticks: ``
If you’re storing a string with double quotes within, use single quotes or backticks
You can also add other variables into a string using string interpolation. To use string interpolation you must
- wrap your string in backticks
- add a dollar sign
- add curly braces
- write your variable inside of the curly braces
Number
- A number is just a number, numbers do not need to be wrapped in quotes like a string.
- Decimal numbers are called
floats
Boolean
- True or False.
undefined
- Variables declared with no value will be
undefined
. - Variables declared with
undefined
will have a value of undefined
null
An empty or a unknown value
Unlike the undefined keyword we are defining a variable with a value of nothing.
- A number too larger to be stored in javascript's number data types
- A value that is unique and unchangeable
Non primitive data types / Collections of data
Object
Objects are written with curly brackets and hold {
key
:value
} pairs..An object's
key
is known as the property (the title of thevalue
its attached to)value
can=
any javascript data type | primitives and non primitivesWe can use Dot Notation to access a objects property and we will get the
value
in return - ex:object.property
Array
- Arrays are "list-like" objects that store multiple data types into a collection
- Arrays are written with brackets
[]
and hold multiple data types that are separated by commas[1,"a",true,null]
- Data in a array can be accessed individually by its index (numbered position in a list, javascript counts from 0) using bracket notation - ex:
array[0]
Operators
- Operators are symbols used to preform operations on values and variables.
Assignment Operator:
- Used to assign values to variables
=
Arithmetic Operators
- Used to preform arithmetic calculations
Using +=
or any arithmetic, assignment operator combination pair will update our initial variables value +=
-=
*=
/=
%=
Comparison operators
- Used in logical statements to determine equality of values or variables, returns a true or false boolean value
- The equal to operator (==) will convert strings into numbers and compare values regardless of data type
- The strictly equal to operator(===) will only return true if both values are equal and have equal date types
- The not equal to operator(!=) will n
Logical Operators
- Used to determine the true or false logic between variables and values
(&&) , (||), (!)
- both values on each side of the and operator must be true for us to get a return value of true
String Operators
- Add strings together. We can combine two strings into one using the
+
operator or the+=
operator
JAVASCRIPT FUNDAMENTALS PART 2... COMING SOON
Top comments (0)