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];
A

e

21
Q

What is the output of:

var lastName = “Marks”;

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

A

k

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]];

A

.

25
Q

how do you access the data inside an array?

A

by using an index

var myArray = ["pigeons","cats","turtles"];
var myData = myArray[0];

Output = “pigeons”

26
Q

What is the output of

var catScores = ["turtles", 44];
var pigeonScore=catScores[1];
A

var pigeonScore=44

an index of 0 would create an output of “turtles” instead of 44

27
Q

Add 4 to the end of the array

var myArray = [3,2,1]

A

myArray.push(4);

myArray now = [3, 2, 1, 4];

myArray.push([4,3])

myArray = (3,2,1,[4,3])

28
Q

What is a function?

A

a reusable piece of code.

example:

function ourReusableFunction() {
  console.log("Kiss puppies");
}

ourReusableFunction();

output is “Kiss puppies”

29
Q

Review this exercise

A

https://www.freecodecamp.com/challenges/passing-values-to-functions-with-arguments

30
Q

Which type of variable of the same name takes precedent?

Global or local?

A

Local

https://www.freecodecamp.com/challenges/global-vs-local-scope-in-functions

31
Q

what is a local variable

A

it is only visible within the function

32
Q

How do you pass values into a function?

A

Arguments

https://www.freecodecamp.com/challenges/return-a-value-from-a-function-with-return

33
Q

How do you send values back out of a function?

A

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
Q

Create a function that allows you to multiply a number by 8

A
function timesFive(num) {
  return num * 8;
}

var answer = timesFive(3);

// 24

35
Q

What are parameters?

A

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
Q

What do you call values that are “passed” into a function when it is called?

A

Arguments

37
Q

How do you add a new value to the end of an array?

A

arrayName.push(x)

38
Q

How do you add a new value to the beginning of an array?

A

arrayName.unshift(x)

39
Q

How do you take away a value from the beginning of an array?

A

arrayName.shift

40
Q

How do you take away a value from the end of an array?

A

arrayName.pop

41
Q

What are boolean’s values?

A

True or False

42
Q

what does “if” do?

A

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
Q

Can an “==” compare two types of data? (Strings and numbers?)

A

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
Q

!=

A

inequality operator. “Not Equal”

examples

1 != 1 // false
1 !=2 // true

45
Q

!==

A

Strict inequality.

will not convert data types

1 !== “1” // true
1 !== 1 // false

46
Q

& &

A

“logical and” operator

You can nest if statements

function inThePocket (val) {

if (val > 3 &amp;&amp; val < 15) { 
     return "in the pocket"
     }
   return "outside the parameters"
}

(Free code camp: comparisons with logical and operator)

47
Q

||

A

“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
Q

How do you chain multiple if statements together

A

by using “else/if”

Function(x){
if (x < 5) { return y };
else if (x > 5) {return z};
else {return q};
}