JS Operators and Methods Flashcards
(54 cards)
1
Q
not
A
!
2
Q
or
A
||
3
Q
and
A
&&
4
Q
how do you create a combination of booleans?
A
() for example
true && (true || false)
will derive true
5
Q
equal to
A
===
6
Q
not equal to
A
!==
7
Q
addition
A
+
8
Q
subtraction
A
-
9
Q
multiplication
A
*
10
Q
division
A
/
11
Q
exponent
A
**
12
Q
modulo
A
%
13
Q
plus equals
A
\+= example: x += y x = x + y incrementing x by y
14
Q
minus equals
A
-=
15
Q
times equals
A
*=
16
Q
divide equals
A
/=
17
Q
absolute value
A
Math.abs( )
18
Q
round up
A
Math.ceil( )
19
Q
round down
A
Math.floor( )
20
Q
parsing an integer
A
parseInt( )
21
Q
parsing a float
A
parseFloat( )
22
Q
generate a number between 0 and 1
A
Math.random( )
23
Q
greater than
A
>
24
Q
greater than or equal to
A
> =
25
less than
26
less than or equal to
<=
27
accessing a character in a string
string[index]
note: the index is the number that corresponds to the location of the character in the string. strings start at 0 in javascript.
28
reassigning a string
```
leave off var, let or const and reassign the variable to the new value;
e.g.
var someVarable = "something";
someVariable = "reassigned string";
```
29
concatenate two or more strings
+
30
string interpolation
+ string interpolation +
31
get the length of a string
.length
32
get the last character of a string
[ .length - 1]
| e.g. "string"["string".length - 1]
33
get a portion of a string
.substring(first index, last index]
i.e. "string".substring(3, 4);
would derive "in"
34
find where a portion of the string exists in a string
.indexOf( )
i.e. "string".indexOf("in");
would derive 3
if it doesn't exist, it derives -1
35
turn a value into a string
.toString( )
36
escape characters
\
37
new line
\n
38
create an array
[ ]
39
access an element in an array
array name [index of element]
e.g.
var array = [1, 2, 3, 4];
```
var secondElement = array[1];
console.log('secondElement:', secondElement)
```
40
reassigning an element in an array
array name [index] = "new value";
| note: arrays are mutable
41
length of an array
.length
42
last element of an array
array name[array name.length - 1]
| almost identical to getting the last element in a string
43
adding an element to the back of an array
.push( )
44
removing an element from the back of an array
.pop( )
45
adding an element to the front of an array
.unshift( )
46
removing an element from the front of an array
.shift( )
47
adding an element in general to an array
```
.splice(index, 0, adding element)
e.g.
var array = [1, 2, 4];
array.splice(2, 0, 3);
derives 1,2,3,4
```
48
removing an element in general from an array
.splice(index, number of removing elements, adding elements if there are any)
49
determine if a value is an array
Array.isArray( )
50
taking parts of an array and creating a new array
.slice(start, end);
51
add an array to another array
.concat
| first array.concat(second array);
52
transform an array into a string
.join( ) all elements added together into a string
.join(" ") adds spaces
.join("-") would add a dash between each element
53
transform a string into an array
.split( ) all elements added together in an array
.split(" ") all elements added individually in an array
.split("-")if elements have dashes, it will add them individually in an array
54
determine where in an array we can find a particular element
.indexOf( )