Learning: The acquisition of skills and the ability to apply them in the future.
What makes an Effective learner?
Why do active learning techniques feel difficult?
Desirable Difficulty
Effective learners space their practice
console.log : command used to print something onto the screen.
code comment : useful for annotating pieces of code to explain how something works, ignored by computer.
“Simplicity is prerequisite for reliability.” – Edsger W. Dijkstra
The number data type in JS is used to represent any numerical values, including integers and decimal numbers.
Basic Arithmetic Operators
Operators are the symbols that perform particular operations.
JS evaluates more complex expressions using the general math order of operations aka PEMDAS.
Modulo : Very useful operation to check divisibility of numbers, check for even & odd, whether a number is prime, and much more! (Discrete Math concept, circular problems can be solved with modulo)
Whenever you have a smaller number % a larger number, the answer will just be the initial small number.
The string data type is a primitive data type that used to represent textual data.
If your string contains quotation marks inside, can layer single or double quotation marks to allow it to work.
"That's a great string"; (valid)
'Shakespeare wrote, "To be or not to be"'; (valid)
'That's a bad string'; (invalid)
indices : indexes of data that begin at 0, can call upon index by using the bracket notation [ ].
console.log("bootcamp"[0]); // => "b"
console.log("bootcamp"[10]); // => "undefined"
console.log("boots"[1 * 2]); // => "o"
console.log("boots"["boot".length - 1]); // => "t"
indexOf() : method used to find the first index of a given character within a string.
The boolean data type is the simplest data type since there are only two values: true and false.
Logical Operators (Boolean Operators) are used to establish logic in our code.
! (not) : reverses a boolean value.
&& (and) Truth Table
Input | Input | Output |
---|---|---|
T | T | T |
T | F | F |
F | T | F |
F | F | F |
|| (or) Truth Table
Input | Input | Output |
---|---|---|
T | T | T |
T | F | T |
F | T | T |
F | F | F |
De Morgan’s Law : Common mistake in boolean logic is incorrectly distributing ! across parentheses.
Short-Circuit Evaluation : Because JS evalutes from left to right, expressions can “short-circuit”. For example if we have true on the left of an || logical comparison, it will stop evaluating and yield true instead of wasting resources on processing the rest of the statement.
All comparison operators will result in a boolean output.
The relative comparators
Fun Fact: “a” < “b” is considered valid JS Code because string comparisons are compared lexicographically (meaning dictionary order), so “a” is less than “b” because it appears earlier!
If there is ever a standstill comparison of two string lexicographically (i.e. app vs apple) the comparison will deem the shorter string lesser.
Difference between == and ===
Variables are used to store information to be referenced and manipulated in a program.
We initialize a variable by using the let keyword and a = single equals sign (assignment operator).
If you do not declare a value for a variable, undefined is automatically set.
let is the updated version of var; there are some differences in terms of hoisting and global/block scope - will be covered later in the course (common interview question!)
Assignment Shorthand
let num = 0;
num += 10; // same as num = num + 10
num -= 2; // same as num = num - 2
num /= 4; // same as num = num / 4
num *= 7; // same as num = num * 7
In general, any nonsensical arithmetic will result in NaN ; usually operations that include undefined.
initialization : process of both declaring and assigning a variable on the same line.
A function is a procedure of code that will run when called. Functions are used so that we do not have to rewrite code to do the same thing over and over. (Think of them as ‘subprograms’)
Arguments : Values passed to the function when it is invoked.
However, is there are not enough arguments provided for parameters our function will likely yield Nan.