Syntax Flashcards
Get a fucking job
What is try…catch?
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.
What’s an exception?
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.
What is the ternary operator?
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.
What is falsy?
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.
What’s an statement?
Syntantic unit that performs an action. It is a command or instruction given to JavaScript engine to execute.
What is truthy?
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 does the && operator work?
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.
What’s if()?
A statement that executes if the specified condition is truthy.
What’s for…of?
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
What’s for…in?
A statement that iterates over all enumerable string properties of an object (ignoring properties keyed by symbols), including inherited enumerable properties.
What are for, for…of, for…in?
Looping constructs. Programming structures that allow to repeat a block of code multiple times.