Syntax Flashcards

Get a fucking job

1
Q

What is try…catch?

A

A statement comprised of a try block and either a catch block, a finally block, or both. The code in the try block is executed first and if it throws an exception, the code in the catch block will be executed. The code in the finally block will always be executed before control flow exits the entire construct.

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

What’s an exception?

A

A condition that interrupts normal code execution.

When an excepction occurs, JavaScript creates an Error, an object that contains information about an error that ocurred during the execution of a program. This object Error is then “thrown”, which interrupts the normal code execution.

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

What is the ternary operator?

A

A conditional operator. It’s the only JavaScript operator that takes three operands:
1. a condition followed by a question mark ?
2. then an expression to execute if the condition is truthy followed by a colon :
3. and finally the expression to execute if the condition is falsy.

Usually used as an alternative to the if…else statement.

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

What is falsy?

A

A value that is considered false when encountered in a boolean context.

JavaScript uses type conversion to coerce any value to a Boolean in contexts that require it, such as conditionals and loops.

Falsy values:
null, undefined, false, 0, -0, -0n, “”, document.all

The values null and undefined are also nullish.

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

What’s an statement?

A

Syntantic unit that performs an action. It is a command or instruction given to JavaScript engine to execute.

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

What is truthy?

A

A value that is considered true when encountered in a boolean context. All values are truthy unless they are defined as falsy.

Examples of truthy values:
if (true)
if ({})
if ([])
if (42)
if (“0”)
if (“false”)
if (new Date())
if (-42)
if (12n)
if (3.14)
if (-3.14)
if (Infinity)
if (-Infinity)

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

How does the && operator work?

A

It is a logical AND operator. Compares two values and returns a boolean.

It uses short-circtuit evaluation: when the first operand is falsy, it will return its value.

It doesn’t always return a boolean. If the first operand is falsy, it returns a falsy value. If the first operand is thruthy, it returns the second operand, regardless of whether it’s truthy or falsy.

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

What’s if()?

A

A statement that executes if the specified condition is truthy.

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

What’s for…of?

A

A statement that executes a loop that operates on a sequence of values sourced from an iterable object. Iterable objects include instances built-ins such as Array, String, TypedArray, Map, Set, NodeList, etc.

for (variable of iterable)
statement

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

What’s for…in?

A

A statement that iterates over all enumerable string properties of an object (ignoring properties keyed by symbols), including inherited enumerable properties.

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

What are for, for…of, for…in?

A

Looping constructs. Programming structures that allow to repeat a block of code multiple times.

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