Basic JavaScript Flashcards

1
Q

Commenting

A

Used to leave notes

Code:
// (for single line code)
/* ... */ (for multi-line code)
How well did you know this?
1
Not at all
2
3
4
5
Perfectly
2
Q

Variables

A
  • Store and manipulate data
  • Store different values
  • Name to represent data
  • Declare a variable
How well did you know this?
1
Not at all
2
3
4
5
Perfectly
3
Q

Assignment operator

A

Code:

Stores a value to a variable.

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

Assigning value to another variable

A

-Use assignment operator

Code:
var a; //no value
a = 7; //has a value
var b; //no value
b = a; //now b = 7
How well did you know this?
1
Not at all
2
3
4
5
Perfectly
5
Q

Initialize a variable

A

-Initial value given to a variable

Code:
var a = 9;
How well did you know this?
1
Not at all
2
3
4
5
Perfectly
6
Q

String literals

A
  • i.e. = string
  • Zero or more characters enclosed in single or double quotes

ex: “your name”

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

String variables

A

A string value assigned to a variable with single or double quotes.

var myFirstName = ‘Lucy’;

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

Uninitialized variables

A
  • Would be ‘undefined’ initially if there is no assigned value.
  • In a mathematical operation, the output would be ‘NaN’ (not a number)
How well did you know this?
1
Not at all
2
3
4
5
Perfectly
9
Q

Case sensitivity

A
  • Use camelCase
  • First letter of first word is lowercase and the first letter of all subsequent words are uppercase.

Code:
myFirstName
myLeastFavoriteAnimal

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

Var and let keywords

A

Var can be overwritten. Could be a problem.

Code:
var camper = 'Fred';
var camper = 'James''
console.log(camper); //James will be printed

Let is better to use. The let variable can only be declared once, if you do not reassign it to a different value.

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

Const

A
  • Read-only
  • Cannot be reassigned
  • Usually written in all caps with underscore for spacing
How well did you know this?
1
Not at all
2
3
4
5
Perfectly
12
Q

Number

A

-Data type which represents numeric data

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

Addition operator

A

”+”

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

Subtract operator

A

”-“

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

Multiply operator

A

“*”

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

Division operator

A

”/”

17
Q

Increment a number

A

Code:
i++; (i = i +1)

Adds 1 to a number

18
Q

Decrement a number

A

Code:

i–; (i = i - 1)

19
Q

Create a decimal number

A

-Sometimes referred to as floating point numbers or floats

20
Q

Remainder operator

A

Code:
“%”
const variable = 11 % 3; // Outputs 2

  • Gives the remainder of the division of two numbers
  • Can be used to check if a number is even or odd
21
Q

Compound assignment (addition)

A
  • (add this to the addition operator card = Everything to the right of the equals sign in evaluated first)
  • Does the math operation and assignment in one step.

Code:
“+=”
let myVar = 1;
myVar += 5; // Outputs 6

22
Q

Compound assignment (subtraction)

A

Code:

“-=”

23
Q

Compound assignment (multiplication)

A

Code:

“*=”

24
Q

Compound assignment (division)

A

Code:

“/=”

25
Q

Escaping literal quotes in string

A
  • Use this when you need a quote inside your quote.
  • Escape a quote with “"
  • Signifies that to JavaScript that it is not the end of the string
Code:
const myStr = "I am a \"double quoted\" string inside \"double quotes\".";