join join the array into a string myArry.join("-")
indexOf find the position of a value myArry.indexOf("s")
concat join two arrays myArry.concat(['a', 'b', 'c'])
some methods alter array value, called the indistinctive method
push add a value to the end of the array myArry.push("a")
pop remove the last value of the array myArry.pop()
null and undefined
null is an intentional lack of value
undefined is a value that is not assigned a value
let a = null null is an intentional lack of value 2. null is not the same as 0
Boolean
boolean is either true or false
not same as "true" and "false"
let name = "Qasim"
name.includes("Q")//returns true
Comparison Operators
let age = 25;
== equal to age == 25
!= not equal to age != 1
<= less than or equal to age <= 25
>= greater than or equal to age >= 25
> greater than age > 25
< less than age < 25
lower case letter are greater than upper case letter
Strict equality === value and type are checked for equality no type conversion
Type conversion
change one data type to another
let age = "25" type conversion age = Number(age)
check type of using typeof
change to a string age = String(age)
change to a boolean age = Boolean(age)
truthy values are positive number and string that is not empty
Implicit conversion is what js does behind the scenes
(control)
conditional statement
if(age < 18) {
} else if(age < 21) {
} else {
}
(flow) control flow
a loop to itirate 10 time and log I
for(let I = 0; I < 10; I++) {
console.log(in loop, I);
}
for array we done know how many elements are there now we can cycle through its length
for(let I = 0; I < myArry.length; I++) {
console.log(in loop, myArry[i]);
}
Bonus create HTML, for in(key), for of(value)
Functions
code gets bigger and bigger gets messy
group section of code together
function myFunction() {
}
args can be empty or pass values to the function
function myFunction(name, age) {
}
code block
function myFunction() {
let name = "Qasim";
let age = 25;
}
function delaration vs function expression
function delaration is when we declare a function and then use it
function expression is when we declare a function and then assign it to a variable
let myFunction = function() {
}
function declaration are hoisted that is they are loaded before the code is run
function expression are not hoisted that is they are loaded after the code is run
Scope
Global scope - variables that are defined outside of a function
Local Scope - variables that are defined inside a function
this keyword
who owns the current space (context)
why would I care about this I am fine with writing same things a million times (I am not I love this keyword)
let myCar = {
make: "Ford",
model: "Civic",
year: "1964BC",
color: "red",
getDescription: function() {
return`Tyler has Honda and Michael has American Honda called ${this.make} made in ${this.year} model ${this.model}`;
}
};