Variables Flashcards

1
Q

What are variables?

A

They are like containers that store information in the computer’s memory. Can be primitive data types

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

What can you do with variables?

A

1) Create a variable with a descriptive name
2) Store or update information stored in a variable.
3) Reference or “get” information stored in a variable

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

Whats the short hand for variable in ES6?

A

var
Note: Variables cannot start with numbers
-are case sensitive
-Cannot be the same as keywords https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Lexical_grammar#Keywords

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

What is the =?

A

the assignment operator used to assign a value to a variable.

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

What is let?

A
signals that the variable can be reassigned a different value. Ex)
let meal = 'Enchiladas';
console.log(meal); // Output: Enchiladas
meal = 'Burrito';
console.log(meal); // Output: Burrito
How well did you know this?
1
Not at all
2
3
4
5
Perfectly
6
Q

What is const?

A

Variable that is constant, cannot be changed

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

What are the math assignment operators?

A

Symbols set to not mathematical operations: -=, *=, and /=
Ex)

let x = 20;
x -= 5; // Can be written as x = x - 5
console.log(x); // Output: 15
let y = 50;
y *= 2; // Can be written as y = y * 2
console.log(y); // Output: 100
let z = 8;
z /= 2; // Can be written as z = z / 2
console.log(z); // Output: 4
How well did you know this?
1
Not at all
2
3
4
5
Perfectly
8
Q

What are the Increment and Decrement Operator?

A

increment operator (++) and decrement operator (–). Communicates the value of variable to increase or decrease by 1

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

How would I write a variable that prints out: ‘I own a pet armadillo.’

A
let myPet = 'armadillo';
console.log ("I own a pet " + myPet + ".");
How well did you know this?
1
Not at all
2
3
4
5
Perfectly
10
Q

What is string interpolation?

A
You to build a string template (Template literal) with backticks (` `) and insert a variable using ${var}
-We interpolate `I own a pet ${myPet}.` into output: 'I own a pet armadillo.'
Ex)
const myPet = 'armadillo';
console.log(`I own a pet ${myPet}.`);
// Output: I own a pet armadillo.
How well did you know this?
1
Not at all
2
3
4
5
Perfectly
11
Q

How do you check for data type of a variable?

A
const unknown1 = 'foo';
console.log(typeof unknown1); // Output: string
const unknown2 = 10;
console.log(typeof unknown2); // Output: number
const unknown3 = true; 
console.log(typeof unknown3); // Output: boolean
How well did you know this?
1
Not at all
2
3
4
5
Perfectly
12
Q

What do you get if variables that have not been initialized display:

A

‘undefined’

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