Javascript Flashcards

1
Q

What Data Types does Javascript use?

A
boolean
undefined
string
symbol
object
null
number
How well did you know this?
1
Not at all
2
3
4
5
Perfectly
2
Q

Declare a variable “cats”

A

var cats;

variables cannot start with a number or contain spaces.

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
3
Q

Which way does assignment go

A

right to left.

For example. Below, myVar gets defined as 5 and then myNum gets defined as myVar (which is currently 5).

myVar = 5;
myNum = myVar;
How well did you know this?
1
Not at all
2
3
4
5
Perfectly
4
Q

what does NaN mean

A

Not a Number

happens when you use an undefined variable in an equation.

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
5
Q

what does i++ operator do?

A

same thing as typing i=i+1

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
6
Q

what does i– operator do?

A

same thing as typing i=1-1

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
7
Q

What does the % operator do?

A

remainder

gives you the remainder of the numbers you are dividing.

4 % 3 = 1

used as a way of testing even and odd numbers. If you remainder anything by 2 it is even if the remainder is 0 and odd if the remainder is 1.

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
8
Q

+= operator

A

does the assignment and addition in one step.

MyVar += 5 means that MyVar is 5 and that you should add 5 to it? I don’t entirely understand how this one works.

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
9
Q

\n

A

new line

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
10
Q

\r

A

carriage return (what is this?)

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
11
Q

what is a carriage return

A

(figure it out)

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
12
Q

\t

A

tab

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
13
Q

\b

A

backspace

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
14
Q

\f

A

form feed

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
15
Q

What do you call it when a + operator is used with a string value

A

concatenation

Example:

var myStr =”This is the start.”+ “ This is the end.”

Output is: “This is the start. This is the end.

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
16
Q

How do you count the number of characters in a string such as the following variable.

Then assign that length to another variable

var catName = “steve”

A

catNumber = catName.length;

The number would be 5 since that’s how many letters are in “steve.” So now catNumber would equal 5

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
17
Q

Use bracket notation to assign the first letter of a last name as a variable to var firstLetterOfLastName.

A
var firstLetterOfLastName = "";
var lastName = "Lovelace";

firstLetterOfLastName = lastName[0];

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
18
Q

in javascript, strings are “immutable” which means what?

A

Once a string is created it cannot be altered once created

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
19
Q

What is the output of the following?

var name = "bob";
var letter = name[2];
A

b

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
20
Q

What is the output of:

var catName = "Jerry";
var letter = catName[catName.length - 4];
21
Q

What is the output of:

var lastName = “Marks”;

var letter = lastName [lastName.length - 2];

22
Q

What is an array

A

It is a type of variable that can store multiple pieces of information.

var array = [“kitty”, 45]

23
Q

What is this?

var ourArray = [[“the universe”, 42], [“everything”, 101010]];

A

It is an array nestled into two arrays.

24
Q

challenge: Type the following in under 20 seconds.

4 tries = good
3 tries = great
1st try = perfect

var myArray = [[“cats”, 43], [“dogs”, 35]];

25
how do you access the data inside an array?
by using an index ``` var myArray = ["pigeons","cats","turtles"]; var myData = myArray[0]; ``` Output = "pigeons"
26
What is the output of ``` var catScores = ["turtles", 44]; var pigeonScore=catScores[1]; ```
var pigeonScore=44 | an index of 0 would create an output of "turtles" instead of 44
27
Add 4 to the end of the array var myArray = [3,2,1]
myArray.push(4); myArray now = [3, 2, 1, 4]; myArray.push([4,3]) myArray = (3,2,1,[4,3])
28
What is a function?
a reusable piece of code. example: ``` function ourReusableFunction() { console.log("Kiss puppies"); } ``` ourReusableFunction(); output is "Kiss puppies"
29
Review this exercise
https://www.freecodecamp.com/challenges/passing-values-to-functions-with-arguments
30
Which type of variable of the same name takes precedent? Global or local?
Local https://www.freecodecamp.com/challenges/global-vs-local-scope-in-functions
31
what is a local variable
it is only visible within the function
32
How do you pass values into a function?
Arguments https://www.freecodecamp.com/challenges/return-a-value-from-a-function-with-return
33
How do you send values back out of a function?
return statements ``` function plusThree(num) { return num + 3; } var answer = plusThree(5); // 8 ``` https://www.freecodecamp.com/challenges/return-a-value-from-a-function-with-return
34
Create a function that allows you to multiply a number by 8
``` function timesFive(num) { return num * 8; } ``` var answer = timesFive(3); // 24
35
What are parameters?
Variables that act as placeholders for the values that will be input into a function. -------------------------------------------------------- Example (a and b are the parameters for functionWithArgs() the function has the console log a + b. bellow there is a call for the function defining the parameters as a="cat," and b = 4. The function would then log cat,4. ``` function functionWithArgs(a,b) { console.log(a+b); } ``` functionWithArgs("cat,",4);
36
What do you call values that are "passed" into a function when it is called?
Arguments
37
How do you add a new value to the end of an array?
arrayName.push(x)
38
How do you add a new value to the beginning of an array?
arrayName.unshift(x)
39
How do you take away a value from the beginning of an array?
arrayName.shift
40
How do you take away a value from the end of an array?
arrayName.pop
41
What are boolean's values?
True or False
42
what does "if" do?
It triggers code to execute inside { } if certain conditions are true or false as defined by conditions in the braces ( ) https://www.freecodecamp.com/challenges/use-conditional-logic-with-if-statements
43
Can an "==" compare two types of data? (Strings and numbers?)
Yes. It has to convert them first, but then can compare them and declare true or false. 1 == 1 // true 1 == 2 // false 1 == '1' // true "3" == 3 // true **************Strict Equality on the other hand === does not convert strings to numbers so the following: 1 === 1 // true 1 === 2 // false 1 === '1' // false "3" === 3 // false
44
!=
inequality operator. "Not Equal" examples 1 != 1 // false 1 !=2 // true
45
!==
Strict inequality. will not convert data types 1 !== "1" // true 1 !== 1 // false
46
& &
"logical and" operator ********* You can nest if statements function inThePocket (val) { ``` if (val > 3 && val < 15) { return "in the pocket" } return "outside the parameters" } ``` (Free code camp: comparisons with logical and operator)
47
||
"logical or operator" returns true if either of the operands is true. Otherwise it returns false. ``` function testLogicalOr(val) { // Only change code below this line ``` ``` if (val < 10 || val > 20) { return "Outside"; } // Only change code above this line return "Inside"; } ``` ``` return testLogicalOr(15) // inside return testLogicalOr(9) // outside ```
48
How do you chain multiple if statements together
by using "else/if" ``` Function(x){ if (x < 5) { return y }; else if (x > 5) {return z}; else {return q}; } ```