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?

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
Name three logical operators
&& = and || = or ! = not
26
How does the logical operator ‘or’ process a set of conditions?
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
How does the ‘not’ operator affect a condition?
The ! operator reverses the boolean value of a condition.
28
Give examples of ‘falsy’ values
1. 0 2. ‘’ or “” 3. NaN 4. undefined 5. null
29
How does the logical operator ‘and’ work?
The && operator evaluates both conditionals and if both are truthy returns the last conditional
30
What is short circuit evaluation?
Short circuit evaluation uses logical operators to make code more concise (but potentially less legible).
31
Given an example of using || in a short circuit evaluation.
let userName = ‘’ let welcome = userName || ‘Stranger’ will set welcome to ‘Stranger’ since userName is falsy.
32
Give an example of short circuit evaluation using && operator.
hasFireworks && makeFestive() if hasFireworks is true then the makeFestive function will be called (because it is truthy).
33
What is the ternary operator in JavaScript
? = ternary operator?
34
How do we use the ternary operator?
The ternary operator can replace an if…else statement. [if statement] ? [ifTrueCode] : [ifFalseCode]
35
What's the difference between a relative and absolute file path?
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
How do you escape a character in JavaScript?
\ - backslash
37
What is a JavaScript expression?
An expression is a valid set of literals, variables, operators, and expressions that evaluate to a single value.
38
What is the assignment operator?
= - the equal sign, because it is used to assign something a value
39
If an if or else…if statement evaluates to true does the code block continue to be read?
No, the code stops at the true conditional and exits the conditional flow.
40
How is switch used for conditional evaluation?
switch can be used to replace multiple if, else…if, else conditionals.
41
Give the syntax of a switch conditional statement.
switch(variableToExamine){ case 'condition1: do code break case 'condition2: do code break default: do code break }
42
Will the switch conditional statement exit code upon a truthy result?
No, without a break statement following a conditional check, all other conditions will be evaluated.
43
What is it called when JavaScript attempts type conversion on the comparison of values?
Casts or casting
44
What is a common use case for the NOT operator?
It is often used to eliminate the else statement in a conditional. if(!variable){ do something if variable is empty}
45
What does the value of undefined indicate?
Basically it indicates the lack of a value. We say something is undefined when it is not explicitly defined
46
What does the value of null indicate?
Null indicates the intentional lack of a value. Developers need to intentionally set a value to null.
47
How to null and undefined compare using strict equality comparison.
They are not equal because they are different primitives.
48
What is scope in relation to variables?
Scope is the context in which our variables are declared and in which context they are available
49
Where are variables in the global scope defined?
Things in the global scope are defined outside of function code blocks.
50
Where are globally scoped variables able to be accessed?
Globally scoped variables can be accessed within any code block in the program.
51
What is block scope in relation to variable declaration in JavaScript?
Block scope indicates that the variable is declared within a block of code.
52
Where is a block scoped variable available
It is available within the block of code in which it is declared (basically within the curly braces)
53
Where do globally defined variables ‘live’ in our code?
They reside in the ‘Global Namespace’
54
What can too many variables in the Global Namespace cause and why is it undesirable?
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
To avoid Scope Pollution what should we do with our variables?
We should scope them as tightly as possible.
56
What are four benefits of tightly scoped variables?
1. Legibility 2. Clarity 3. Maintainability 4. Performant