Day 2 Flashcards
The _____ and ______ were introduced in ES6, making them a modern JS syntax. They are a new way of declaring variables.
let and const
While the _____ variable is the old way of declaring variables.
var
We use _____ keyword to declare variables that can change values later.
let
When you change the value of a variable, its technical term is called _________ a value.
Reassigning or mutating
We also use let whenever we want to declare ______________. It is a common practice to declare variables with empty values (usually at the top of the file) and then reassign them later.
empty variables
On the other hand, we use the _______ keyword to declare variables that are NOT supposed to change at any point in the future. So the values declared with this cannot be changed.
const
You will get a _______________, if you attempt to change the value of a variable declared with const.
TypeError
In techical terms, variables declared with const are ___________ variable.
immutable
True of false: Now the fact that variables created with const are immutable, it also means that we CANNOT declare empty const variables.
True
True of false: You can declare empty variable with const.
False - variables declared with const are immutable.
Is this valid: const job;
No. You can’t declare an empty variable with const, you need to assign them with an initial value (initializer)
Basically, we need an ________ value (or __________) when using const declaration.
Initial or initializer
True of false: It is a best practice to always use const by default and let only if you are really sure that the variable needs to change at some point in the future.
True
True of false: It is a best practice to have as little variable mutation or variable changes as possible, because changing variables introduces a potential to create bugs.
True
Another way to declare variables, but should now be avoided.
var
Prior to ES6, _____ is used to create variables.
var
At first sight, it works pretty much the same as let.
var
True or false: It’s recommended to still use var in modern JavaScript.
False - use let or const instead
True or false: You can actually declare a variable without the use of let, const, or var but it’s a bad practice, and you’ll learn more later why.
True
This operators perform arithmetic on numbers (literals or variables).
Arithmetic operators
True or false: You can log multiple values in console.log(ageJonas, ageSarah)
True
True or false: You cannot perform arithmetic operations inside of console.log()
False - you can
What is exponentiation operator looked like?
**
True or false: We can use the plus operator to join or concatenate strings.
True
Given that the variables are declared. Is this valid: console.log(firstName + ‘ ‘ + lastName);
Valid
Operator used to assign values to a variable
Assignment operator
This operator adds the value of the right operand to a variable and assigns the result to the variable.
addition assignment operator (+=)
This operator increments (adds one to) its operand and returns the value before or after the increment, depending on where the operator is placed.
increment operator (++)
We use ___________ operators to produce boolean values.
comparison (and of course logical)
True or false: The Console tab in developer tools has access to all variables in present in the browser tab.
True
JavaScript has a well-defined order of operator ___________. Basically, the order in which operators are executed.
precedence
True or false: Comparison operators has lower precedence than arithmetic operators. This means arithmetic operators executes first than comparison operators.
True
True or false: Most of the operators execute from left to right, but some execute from right to left like assignment operator.
True
True or false: You can declare two empty values: let x, y;
True
Give a type of operator that has right to left associativity
Assignment operator or exponential
What will be the value of x and y: x = y = 25 - 10 - 5;
10 and 10
Which has the highest order of precedence?
Grouping
What is the result: const ageAverage = 20 + 20 / 2;
30
What is the result: const ageAverage = (20 + 20) / 2;
20
It’s easier to building strings using _______________.
Template literal
Starting ES6, there’s a much easier way to concatenate strings with __________.
Template literal
We use ____________ to write template literals, and we can wrap variables inside of __________.
Backticks (``) and interpolation ${}
True or false: You can also write regular strings using template literals.
True
You can write multi line strings much easier with ______________.
template literals
Use the_______________ to specify a block (code inside curly braces) to be executed if a condition is true.
if statement
The ________________ is executed when if statement or else if statement are not executed.
else statement
The if else statement is called a _________________. They are commands that enable a program to “take decisions”, following one path or another.
control structure
True or false: It’s important to remember that any variables we declare inside of a code block cannot be accessible outside of the code block.
True
When we manually convert from one type to another.
Type conversion
To convert a string to a number we use the ____________ function.
Number()
What happens if we try to use Number() function but the string does not contain number? What will it return?
NaN
JS will return _______ when an operators that involves numbers failed to produce a new number. It actually means ______________, not ‘not a number’.
NaN, invalid number
Now to convert a number to a string we use _____________ function.
String()
When JavaScript automatically converts types behind the scenes for us.
Type coercion
True or false: We rarely do type convertions since JS automatically converts types for us.
True
True or false: Basically, type coercion happens whenever an operator is dealing with two values that have different types.
True
True or false: The plus operator will convert strings to numbers.
False - The plus operator will convert numbers to strings.
True or false: The minus operator triggers the opposite conversion, it instead converts strings to numbers.
True
True or false: Other arithmetic operators like multiplication and division will convert string to a number.
True
True or false: When we compare strings (that looked like numbers) using logical operators, it will result to Error.
False - When comparing the strings it will be converted to numbers automatically.
The _______ values are values that are not exactly false, but will become false when we try to convert them into a Boolean.
falsy
In JS, there are only five falsy values. These are:
0, empty string, undefined, NaN, null
True or false: Everything else, are considered truthy values.
True
We use the _______________function to find out if an expression (or a variable) is truthy or falsy:
Boolean()
When does JS do type coercion to Booleans?
When you use a value (other than Boolean) as condition to your if statements. It will convert them to either truthy or falsy value.
What are the two types of equality operators?
Strict equality operator (===) and Loose equality operator (==)
True or false: Whenever our if block only has one line of code to execute, the use of curly braces is unnecessary.
True
The strict equality operator is strict because it does not perform ______________. It only returns true if both values are exactly the same and its type is also the same.
type coercion
What is the result: console.log(’18’ === 18);
false
On the other hand, the ___________________ operator does type coercion.
loose equality operator (==)
What is the result: console.log(’18’ == 18);
true
What is strict inequality operator syntax looks like?
!==
The ________________ is a branch of computer science, which uses true and false values to solve complex logical problems.
Boolean logic
We will only learn the three most basic logical operators which are the ______ operators
AND, OR, and NOT
Returns true only if two values or more values are true. Basically, it will only return true if all are true.
AND
Returns true even if there is only one true.
OR
It does not combine multiple values. Instead, this operator only acts on one Boolean value and basically inverts it.
NOT
True or false: The NOT operator has lower precedence over the AND and OR operator.
False - The NOT operator has higher precedence over the AND and OR operator.
What is the syntax of AND operator?
&&
What is the syntax of OR operator?
||
What is the syntax of NOT operator?
!
An alternative way of writing complicated if else statements
switch statement
Write down a boilerplate for a switch statement.
switch(), then curly brackets, inside of it is case:, and should have break;. It also contains a default:
True or false: With switch statements, we can run the same code for multiple cases.
True
True or false: We don’t need to put break; after every case.
False - We need to put break; after every case.
In a switch statement, the __________ will execute if none of the cases are executed. Like else.
default
True or false: If you omit the break; the code simply continues executing until it sees a break;.
True
An ____________ is a piece of code that produces a value.
expression
A bigger piece of code that is executed and which does not produce a value on itself.
statements
Term for ‘sequence of actions’
statements
In a template literal, we can only put expressions not _____________.
statements
What do we call this ${}
Interpolation
We already saw two ways of writing conditionals. The regular if else statement and switch statement. But there is another one, and that is the _________________.
conditional (ternary) operator
Theconditional (ternary) operatoris the only JavaScript operator that takes three operands, which are:
The condition, followed by a question mark (?), then an expression to execute if the condition istruthyfollowed by a colon (:), and finally the expression to execute if the condition isfalsy.
True or false: The conditional operator allows us to write something similar to an if else statement but all in one line.
True
True or false: It’s called ternary operator because it has three parts: the condition, the code executed for if part, and then the code executed for the else part.
True
True or false: Now the conditional operator is in fact an operator, and an operator always produces a value. So in other words an operator is an expression, right?
True
True or false: The ternary operator does not replace the if else statement, we still need if else statement when we’re writing code that needs more option (else if). The ternary operator is only good when we just need a quick decision.
True
Can you put conditional ternary operator inside the interpolation of a template literal?
Yes. It’s valid.
Netscape Navigator, a dominant browser at its time, hired a guy named __________ to create a very first version of JS.
Brendan Eich
Brendan Eich creates the very first version of JS in just ___ days. It was called _______, but already had many fundamental features of modern JavaScript!
10, Mocha
Mocha changes to __________ and then to JavaScript, in order to attract Java developers. However, JavaScript has almost nothing to do with Java.
LiveScript
Microsoft launches IE, then copied JS from Netscape and called it _______.
JScript
Year when JS was invented
1995
ES6 is also called _______.
ES2015
They need to standardize the language, __________ releases ECMAScript 1 (ES1), the first official standard for JS (ECMAScript is the standard, JS is the language in practice)
ECMA
Year when ES5 is introduced.
2009
True or false: Code back all the way from 1997 will still work on modern browsers. This means that modern browsers are backwards compatible.
True
The concept of _______________ means that there is almost never anything removed from the language, but only added in new versions. Not really new versions, just incremental updates (releases)
Do not break the web
JavaScript is not ____________ compatible simply because there is no way browsers from today can understand the updates that is coming from the future.
forwards
True or false: It’s still important to understand old JS syntax like ES5.
True - since some older code bases are written in ES5.