JavaScript : notes, terms, definitions, etc..
Future topics to do :
drag and drop
transition
type coercion :
js auto converts number to spring when you display or print the variables
event he boolean is converted to a string for display
variable mutation :
js can dynamically change datatype for you when you change a veriable to another data time
example :
var size=39;
size = "big";
operator precedence :
numbers in quotes execute first before plus or minus before greater then and equal to
See full table here
falsy values :
undefined, null, 0, NaN
will all become false when evauted in a condition statement
truthy values :
are all values not falsy
Execution stack :
JS execute in order top to bottom code, it will stop once an error is found
Scope :
The environment or space where a variable is defined and can be accessed.
In JS a new function creates a new scope
Lexicon Scope :
If a function is within another functions, the variables in the inner
function can also has access the variables in the parent function
Example
var a = 'Hello'; //global scope
function first();
function first() { //1st scope
var b = 'Bill';
function secound() { //2nd scope
var c = 'Walter';
var all = a + b + c;
}
}
This keyword :
Is not assigned until a function where it is defined is called
regular call points to the global object, which is the window.
Method call points to the object that is calling the method
How to get element
Get by class name
var button = document.getElementsByClassName("button_phrases");
get by id
var link = document.getElementById("link-id");
operators
typeof
var name="john";
if (typeof name == 'string') {
//execute this code if var name is a string
}
possible values returned by the typeof
"object"
"boolean"
"function"
"number"
"string"
"undefined"
Break & Continue
Use break to stop a loop if a condition is true.
Use continue to keep running a loop
These to code can be placed anywhere inside a loop
conditional
if else -
if (x='ben') {
//execute this code//execute this code
} else if () {
//execute this code
} else {
//execute this code
}
Ternary
(condition) ? //execute this code : //execute this other code
(age < 18) ? console.log("Too young"):console.log("Old enough");
18> variablename = (condition) ? value1:value2
var voteable = (age < 18) ? "Too young":"Old enough";
switch
switch (variable) {
case "apple":
//execute this code
break;
case "orange":
//execute this code
break;
default:
//execute this code
}
Loops
For Loop
for (var i = 0; i < 5; i++) {
text += "The number is " + i + "<br>";
}
executes while value exists in variable cars
for (var i = 0; i < cars.length; i++) {
text += cars[i] + "<br>";
}
Looping backwards
for (var i = cars.length - 1; i>=0; i--) {
text += cars[i] + "<br>";
}
While Loop
while (i < 10) {
text += "The number is " + i;
i++;
}
Advance topics to review
Javascript Objects, inheritance, instances, prototype, Object.create, Javascritp Canvas, class
ES6 Review
string methods to review startsWith, endsWith, includes, repeat, sub-class : class extends, Promises, async function,
Arrow Function =>
Destructing take data such as an array and put them in a variable
XXXXXX