General - Beginning Flashcards

1
Q

Name Three ways to define variables in JavaScript

A

var, let, const

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

Give the definition of an “operator” in JavaScript.

A

An operator is a character or phrase that performs a task in our code.

typeof is an operator

(Arithmetic operators: + - * / %, etc)

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

In a general sense, what is a “property” of a data type in JavaScript

A

Property in regards to data types would be information automatically generated about the data type in question.

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

What is a method in JavaScript?

A

A method is a function that is a property of a Primitive Type or an Object.

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

How do we invoke or call a method in JavaScript.

A

Methods are attached to their Primitive Type or Object with the dot operator (.) and Empty Parenthesis ().

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

What are the 8 fundamental data types in JavaScript?

A
  1. String
  2. Number
  3. Boolean
  4. Null
  5. Undefined
  6. Symbol
  7. BigInt
  8. Object
How well did you know this?
1
Not at all
2
3
4
5
Perfectly
7
Q

What is a mathematical assignment operator?

A

Mathematical assignment operators are built-in operators in javascript that help with incrementation. For example:

+=

-=

*=

/=

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

What is the equivalent mathematical assignment operator to z = z + 1?

A

z += 1

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

What is the z *= 2 equivalent to without using a mathematical assignment operator?

A

z = z * 2

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

z = 5

z -= 1

z = ?

A

z = 4

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

z = 6

z /= 2

z = ?

A

z = 3

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

What is the increment operator in JavaScript and how is it used?

A

++

This mathematical assignment operator increase the value of something by 1

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

What does the following represent and what is its function?

A

This is the decrement operator.

The decrement operator is a mathematical assignment operator that decreases the value of something by 1

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

How can we check the type (data type) of a variable

A

We can use the ‘typeof’ operator in JavaScript.

console.log(typeof variableName)

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

What are the two broad types of Methods in JavaScript.

A

Instance Methods - methods called on an object instance

Static Methods - methods called on an object constructor, not on an instance.

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

What does it mean that JavaScript is weakly typed?

A

To be weakly typed means that we do not need to declare the type of data being stored in a variable.

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

What is a conditional statement in JavaScript

A

A statement that checks a certain condition and performs an action based on that condition

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

Give the syntax of an ‘if’ statement

A

if(condition){code block/block statement}

if condition evaluates to true, the code block will be executed

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

Where would we use an if…else statement

A

When we have a binary decision that can evaluate to true or false

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

What is the syntax of an else statement (assume the presence of an if statement)

A

else{code block/block statement}

when the if-statement evaluates to false the else code block will execute.

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

List the comparison operators

A
  1. < less than
  2. > greater than
  3. < = less than or equal to
  4. > = greater than or equal to
  5. === strictly equal to
  6. ! == not strictly equal to
How well did you know this?
1
Not at all
2
3
4
5
Perfectly
22
Q

What is the identity operator?

A

===

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

What is the equality operator?

A

==

24
Q

How do the identity operator and equality operator differ

A

The equality operator ( == ) attempts to unify the data-types before comparison

The identity operator ( === ) will not attempt type conversion before comparison

25
Q

Name three logical operators

A

&& = and

|| = or

! = not

26
Q

How does the logical operator ‘or’ process a set of conditions?

A

The || operator evaluates the first conditional, if ‘true’ it does not check the second condition.

If the first conditional is false, then the || operator checks the second condition

27
Q

How does the ‘not’ operator affect a condition?

A

The ! operator reverses the boolean value of a condition.

28
Q

Give examples of ‘falsy’ values

A
  1. 0
  2. ‘’ or “”
  3. NaN
  4. undefined
  5. null
29
Q

How does the logical operator ‘and’ work?

A

The && operator evaluates both conditionals and if both are truthy returns the last conditional

30
Q

What is short circuit evaluation?

A

Short circuit evaluation uses logical operators to make code more concise (but potentially less legible).

31
Q

Given an example of using || in a short circuit evaluation.

A

let userName = ‘’

let welcome = userName || ‘Stranger’

will set welcome to ‘Stranger’ since userName is falsy.

32
Q

Give an example of short circuit evaluation using && operator.

A

hasFireworks && makeFestive()

if hasFireworks is true then the makeFestive function will be called (because it is truthy).

33
Q

What is the ternary operator in JavaScript

A

? = ternary operator?

34
Q

How do we use the ternary operator?

A

The ternary operator can replace an if…else statement.

[if statement] ? [ifTrueCode] : [ifFalseCode]

35
Q

What’s the difference between a relative and absolute file path?

A

A relative path references the file based on the current directory

An absolute path references the file based on the root or HTTP location

36
Q

How do you escape a character in JavaScript?

A

\ - backslash

37
Q

What is a JavaScript expression?

A

An expression is a valid set of literals, variables, operators, and expressions that evaluate to a single value.

38
Q

What is the assignment operator?

A

= - the equal sign, because it is used to assign something a value

39
Q

If an if or else…if statement evaluates to true does the code block continue to be read?

A

No, the code stops at the true conditional and exits the conditional flow.

40
Q

How is switch used for conditional evaluation?

A

switch can be used to replace multiple if, else…if, else conditionals.

41
Q

Give the syntax of a switch conditional statement.

A

switch(variableToExamine){

case ‘condition1:

do code

break

case ‘condition2:

do code

break

default:

do code

break

}

42
Q

Will the switch conditional statement exit code upon a truthy result?

A

No, without a break statement following a conditional check, all other conditions will be evaluated.

43
Q

What is it called when JavaScript attempts type conversion on the comparison of values?

A

Casts or casting

44
Q

What is a common use case for the NOT operator?

A

It is often used to eliminate the else statement in a conditional.

if(!variable){ do something if variable is empty}

45
Q

What does the value of undefined indicate?

A

Basically it indicates the lack of a value.

We say something is undefined when it is not explicitly defined

46
Q

What does the value of null indicate?

A

Null indicates the intentional lack of a value.

Developers need to intentionally set a value to null.

47
Q

How to null and undefined compare using strict equality comparison.

A

They are not equal because they are different primitives.

48
Q

What is scope in relation to variables?

A

Scope is the context in which our variables are declared and in which context they are available

49
Q

Where are variables in the global scope defined?

A

Things in the global scope are defined outside of function code blocks.

50
Q

Where are globally scoped variables able to be accessed?

A

Globally scoped variables can be accessed within any code block in the program.

51
Q

What is block scope in relation to variable declaration in JavaScript?

A

Block scope indicates that the variable is declared within a block of code.

52
Q

Where is a block scoped variable available

A

It is available within the block of code in which it is declared (basically within the curly braces)

53
Q

Where do globally defined variables ‘live’ in our code?

A

They reside in the ‘Global Namespace’

54
Q

What can too many variables in the Global Namespace cause and why is it undesirable?

A

They can cause Scope Pollution

It is undesirable because it can be hard to keep track of many variables and there can be unexpected consequences of collisions an accidents.

55
Q

To avoid Scope Pollution what should we do with our variables?

A

We should scope them as tightly as possible.

56
Q

What are four benefits of tightly scoped variables?

A
  1. Legibility
  2. Clarity
  3. Maintainability
  4. Performant