Js Flashcards
How can we deleet everything in chrome Console ?
type: clear
or
ctrl + k
How to get to console directly ?
command + option + j
or
got to view => developer=> javascript console
+
addition
-
subtraction
*
Multiplication
/
Division
%
Modulo
what is prder operations ?
PEMDAS
what is PEMDAS
parantheses, exponents, Multiplication, division, addition, substraction
how can i recall previous run lines ?
with up/down arrow
how tp make a comment in Js ?
with //
modulo known also as ?
remeinder operator
how to to pronaunce modulo ?
madulo
what means 9%2
it means two goes into nine how many time as a whole number, and how much will be remain ?
9%2 = 1
modulo ist commen to use where ?
to determine if a number is even or odd
how to write 2²?
2**2
what Nan stand for ?
not a number
NaN consider as what is js ?
consider as a number
0/0 =
NaN
how to check js consider an ellement as what ?
with command typeof
ex: typeof 4 = number
what is variable ?
it is the way of giving some name to a value and sorting it using js.
how we make a variable ?
let year =. 1985;
how to update the value of a variable ?
imagine we have let numApple = 4;
- write it again : numApple = 5;
or
-numApple = numApple + 1
or
-numApple +=5
-numApple -=5
- if i had totalFruits= numApple + num Orange in previouse liene and than I updated numApple, how can i update totalFruits value ?
just write totalFruits= numApple + num Orange again
score ++; =
score+=1;
score–; =
Score-=1;
what Const stand for ? and what is it ?
Constant, it is a value that does not change
What is VAR ?
BEFORE LET AND CONST, VAR was the only way of Declaring variables. these days it is not commen to use.
How many optons do we have for a Boolean value ?
two, true or false
Whats is Booleann use to ?
to store yes or no, True or false
Ex numPuppies = false;
js hard ruls:
-we cant have space between our name
- we cant have number at begining of my name
- the Names are case sensitiv
these names can contain also $ and
what is the other name for Number ?
identifier
what is the name of this type of typing numberOfBoys ?
camel cased
by Boolean it is better how to name them ?
instead of gameOver = True;
isGameOver
What is String ?
It textual information, they reprecents text, and they must be wrapped in quots.
let username = “pouya”;
- we can have space in between
-we can have $
-we can have numbers
-it can be zero character lang
- we can use one string inside another string
“I´love´you “
- we cant do like that
“I”love”you “
string index start with which number ?
0
How can I access indexes of my string ?
let animal = “cat”;
animal[1] = “a”
what is concatenation ?
“lol”+”lol”= “lollol”
a combination of number and string is :
string
msg.toUppercase ()
what is toUpperCase () ?
it is a method
with which method can we upper case our string ?
.toUpperCase ()
with which method can we lower case our string ?
.toLowerCase ()
what is trim Method ?
it is going to trim off any whitespace at the begining of a string or at the end.
we can chain methids together
.
what is arguments ?
are inputs that we can pass into the method to alter how they behave
ex: searchFor(“a”) “a” is an argument.
what is indexOf method?
its going to give us the string index and positional number where a given argument occurs in a string.
what is slice method?
it can accept more than one argument .
it is going to extract or slice a portion of a string and it returns it or give it to us as a new string.
let msg = “haha that is so funny!”
msg.slice(5) =”that is so funny!”
or
“haha that is so funny!”.slice(5)
or
msg.slice(5, 10)
what is replace method?
msg.replace (“haha”,”lol”)
what is repeat method?
“lol”.repeat(10) = “lollollollollollollollollollol”
what is Template Literal ?
these Templates allows us to create strings where we can embed an expression inside the string and that expression will be evaluated and turned into a string.
´I counted ${x+y} sheep´
Template Literals only works with back ticket, what is back ticket ?
´´
what is the pronaunciation for null
nol
what is undifined
it is the way of js sayin, I dont know. I dont know what do you want.
what is null
it is a value we can set for a variable
what is The Math object ?
it´s a collection of properties and methods that have to do with math in some way.
what is math.floor ?
it will take a number with a decimal and chop of that decimal, so it´s not rounding.
Ex: math.floor (23.9999999) = 23
Math.ceil (34.1) =
35
what is math.random ()
it will give us random numbers between 0 an 0.999999999
make random number beween 1 and 10
Math.floor(math.random()*10)+1
>
greater than
<
less than
> =
greater than or equal
==
equality
!=
not equal
===
strict equality
!==
strict non equality
what is unicode ?
underlying code of every character
what is the diffrence between == and ===
===checks the type too
how we print our arguments in js ?
console.log()
alert
it gonna pop up an alert user
prompt
it is gonna accept an argument
how do i connect my html and js
I will write
in the end of my body in html
what is if statement ?
my code will run if given condition is true
let rating =3;
if (rating===3){
console.log(“You are a super star”);
}
what is else if statement ?
if the if part was false, then maybe try this other thing
et rating =3;
if (rating===3){
console.log(“You are a super star”);
}
else if (rating===2){
console.log(“Meets Expectitations”)
}
* we can have as many else if as we want
is the order of else ifs matter ?
yes, so much
what is else statement ?
else going to be the last part. it is always last piece.
if (rating===3){
console.log(“You are a super star”);
}
else if (rating===2){
console.log(“Meets Expectitations”)
}
else {
console.log(“Meh”)
}
every single value in js have truthy exept
1- false
2- 0
3- “” (empty string
4- null
5- undifined
6-NaN
(these are falsy)
what is logical operators ?
logical operators are operators that allow us to combine diffrent expressions
logical operators => and
&&
logical operators=> or
II
logical operators=> not
!
in order to logical operator ´and´ gonna be true, what is important ?
the left and right side must be true
in order to logical operator ´or´ gonna be true, what is important ?
it doesnt need both part to be true, in order whole thing to be true, it just need one part to be true
what does ´not´ logical operator ?
it is going to negate the value, if its true it will change it to false, if its fals it change it to true
what is Arrays ?
-it is a collection of values.
-it is an ordered collection of values
- it is an array: []
imagine we have this array:
days[1] = “Tursday”
How can I get “T” from it ?
days [1][1]
how can we update an array ?
by typing it again with the new value
how to update a string ?
it is not possible
what does ´push and pop ´
it allow us to add and remove from the end of an array
How to use push ?
let movie = [“tom”,”jerry”]
movie.push (“alice”,”elford”)
how to use pop ?
movie.pop() and it will remove an element from the end
what is shift and unshift ?
shift removes from the beginning of an array
unshift remove add to beginning
how we use shift ?
movie.shift()
How to use unshift ?
movie.unshift (“jordan”,”petter”)
what is concat ?
we mix two array and become the third array
How do we use concat ?
let cat = [“kitty”,”blue”]
let dog =[“dokme”,”chakme”]
cat.concat(doge)
what is includes ?
it show us if an array contain a value in true or false.
cat.includes(“party”)
what is a Reverse ?
it is going to reverse an array.
what else happens when i use reverse ?
the original array also will be modified
what are slice and splice ?
slice is the way of copying a slice of an array and
splice is going to change content of an array by removing or replacing existing elements or adding new ellements in place
how to use slice ?
colorsd.sliche(3 )
it will start from 3 toward
colorsd.sliche(3, 5 )
it will take slice between index 3 and 5
how to use splice ?
colors.splice (5,1)
it will remove one element at index 5
colors (5, 0, “red”)
at index of 1 it wiill remove nothing and just add red after that
what is sort ?
if we just call array.sort() , it will change it to a string
How to update a Const ?
it is not possible in normal way.
- it is possible if we mix it with array
ex:
const nums =. [1, 2, 3]
imagine I have
const gane =[[“x”,”o”,”x”],[“o”,”null”,”x”],[“o”,”o”,”x”]]
how can i access null ?
game[1][1]
js objects are made from what ?
key and value
let comment = {
username: “pouya”,
age : 30
tags: [ “#A”, “#B”, “#c”]
};
how can we access pouya in this js object ?
key and value
let comment = {
username: “pouya”,
age : 30
tags: [ “#A”, “#B”, “#c”]
};
comment[“username”]
or
comments.username
I have
const midterm {daniel: 79, susane: 89, marta: 70}
How can i update susane midterm ?
and how can i add a mark for azra ?
midterm.susane = 95;
midterm.azra = 80
write a for loop
for (let i = 1; i++){
console.log(i);
}
write a infinate loop
for (let i = 20; i>= 0; i++) {
console.log(i)
}
write loop for
const animals = [ “lions”,”cats”,”dogs”];
I expect the resault will be
0 “lions”
1”cats”
2”dogs”
for (let i = 0; i<animals.length; i++) {
console.log(i, animals[i]);
}
which alphabet do we usualy use for for loop?
which alphabet do we usualy use for first nested for loop ?
which alphabet do we usualy use for second nested for loop ?
which alphabet do we usualy use for third nested for loop ?
1- i
2- j
3- k
4- m
5- .
.
.
.
We have
const seatingChart = [
[“kristen”,”erik”,”namita”],
[“geoffery”,”julia”,”antonio”,”kevin”],
[“yuma”,”sakura”,”jack”,”erika”]
]
how can we print out every name ?
for (let i = 0; i <seatigChart.length; i++) {
const row = seatigChart[i];
console.log(´ROW ${i+1}´)
for (let j = 0;vj <row.length; j++){
console.log([j])
}
}
what is while loop
it has only one single condition and as long as this condition is true, our loop will continue to run.
write a while loop
let num = 0;
while (num<10) {
console.log(num);
num++;
}
what is the break keyword in js
-it usually use in while loop
-it causes the loop to exit immediately
what is for… of
for…of allows you to iterate over the values of an iterable object like arrays, strings, maps and sets.
Syntax: ´for (const value of iterable) { // code }´
Use ´for…of´ when you need to iterate over the values of an iterable object, rather than the index.
can use for…of only with what ?
only with iterable object
what is for… in
-it is pretty uncommen these days.
-it will give us only key in the object
what shold i di by for in if I want for … in too ?
for (let person in testScores){
console.log()´${person}scored ${testScores[person]}´);
}
how many steps do we have to write an object ? what are them?
two steps:
1- define the function
2- execute it
write a sample function
function functionName(){
//do something
}
funcName()
what is argument ?
argument in js is fancy way of saying inputs to a function
function greet(firstName) {
console.logi(´firstName is: ${firstName}´)
}
====>firstName is an Argument
write a function with multiple arguments
function greet(firstName,lastName) {
console.log(´Hey there, ${firstName}!´)
}
What is Return ?
to have capturable value from function we need Return.
so instead of :
function add(x,y){
console.log(x+y)
}
we write:
function add(x,y){
return x+y;
}
console.log(x+y)
what should be know about return keyword ?
-return keyword actually stops the execution of our function so wherever I have something aftewards, like console.log() , this line will not run
-we can only return a single value