- Welcome Lecture
- Morning Lecture
- Solo Work!
should feel challenged
throughout the courseconsole.log
is a function in javascript which ‘prints’ or ‘logs’ the return value of the inputted code to your console. console.log(1 + 1); // 2
console.log(2.5 - 2); // 0.5
console.log(3 * 4); // 12
console.log(10 / 2); // 5
// Modulo (%) calculates remainder
console.log(25 % 5); //5r0 -> 0
console.log(26 % 5); //5r1 -> 1
console.log(27 % 5); //4r2 -> 2
.length
method returns the number of characters in a string:
'code'.length
-> 4Index
” as the positioning of elements // length
console.log('code'.length);
// using brackets
console.log('code'[0]); // 'c'
console.log('code'[1]); // 'o'
console.log('code'[2]); // 'd'
// indexOf
console.log('code'.indexOf('c')); // 0
console.log('cool code'.indexOf('o')); // 1
console.log('cool code'.indexOf('a')); // return undefined
true
or false
!true
-> false
instead of true
true && false
-> falseA | B | A && B |
---|---|---|
true | true | true |
true | false | false |
false | true | false |
false | false | false |
true || false
-> trueA | B | A || B |
---|---|---|
true | true | true |
true | false | true |
false | true | true |
false | false | false |
// Less than/Greater than
console.log(5 < 9); // true
console.log(5 > 9); // false
console.log('a' < 'b'); // true (dictionary order)
console.log('cat' < 'cats'); // true (dictionary order)
// Inclusive comparison
console.log(7 <= 10); // true
console.log(10 >= 10); // true
// Equality === and !==
console.log(2 === 2); // true
console.log(2 === 2.1); // false
console.log(2 !== 2.1); // true
// Two equality operators, === and ==
console.log(5 === '5'); // false
console.log(5 == '5'); // true (types are coerced)
console.log([] == 0); // true (can be unpredictable)
// initialization:
// - declaration, creating the space for the variable
// - assignment, giving a value to the variable
let state; // declaration using javascript 'let'
console.log(state);
state = 'California'; // assignment
console.log(state);
let city = 'Sacramento'; // both (i.e. initialized in one line)
console.log(city);
// more assignment
let age = 5;
console.log(age); // 5
age + 5; // no assignment used, i.e. change not permanent
console.log(age); // 5
age = age + 5; // assignment is used, change is permanent
console.log(age); // 10
age += 5; // assignment is used, this is shorthand
console.log(age); // 15
// Using ++ and --
age++;
console.log(age); // 16
age--;
console.log(age); // 15
// keyword name parameters code block
function nameOfFunction(parameter1, parameter2){
// code to run whenever we invoke/call the function
}
return
keywordundefined
.If we want to return anything else, we use the return
keyword:
The return
keyword stops executing code, nothing else below is run