- Primitive types
- Operators
- Comparison and equality operators
- Arithmetic operators
- Logical operators
- Control Structures
if ... else if ... else ...switchforloopwhileanddo whileloops
- Functions
- Declaration
- Call
- Function hoisting
- Anonymous self-invoking function
- Optional parameters
- Arguments array
- Recursion
- Lambda notation
- Scopes
var,let,const- Callback pattern & pass function as parameter
- Call by value vs. call by reference
- Objects
- Declaration
- Object scope and
this - Functions and objects
- Functions as objects
newoperatorcall()andapply()
- Prototypes
Is data that is not an object and has no methods.
Number: JavaScript has only one type of numbers. Numbers can be written with, or without decimalsBoolean: Boolean represents a logical entity and can have two values: true, and falseString: JavaScript's String type is used to represent textual data. It is a set of "elements" of 16-bit unsigned integer values.Array: Arrays are regular objects for which there is a particular relationship between integer-key-ed properties and the 'length' property.Type conversion: Number() converts to a Number, String() converts to a String, Boolean() converts to a Boolean, parseInt() Parses a string and returns an integer.
- Comparison and equality operators
- Comparison operators output true or false by comparing values.
>, <, >=, <=, ===, and !== - Arithmetic operators
- Arithmetic operators take numerical values (either literals or variables) as their operands and return a single numerical value.
+, -, * and / - Logical operators
- Logical operators combine multiple Booleans or Values and output a single boolean.
&&, ||, and !
Source: codeacademy/comparison_logical and dev.moz/arithmetic_operators
The current context of execution. The context in which values and expressions are "visible," or can be referenced. If a variable or other expression is not "in the current scope," then it is unavailable for use. Scopes can also be layered in a hierarchy, so that child scopes have access to parent scopes, but not vice versa.
-
var,let,const– variable typesvar: Globally scoped or function/locally scoped, can be re-declared and updatedlet: Preferred for variable declaration now, block-scoped, can be updated but not re-declared.const: Maintain constant values. const declarations share some similarities with let declarations. cannot be updated or re-declared
-
Callback pattern & pass function as parameter:
A callback function is a function passed into another function as an argument, which is then invoked inside the outer function to complete some kind of routine or action.
function greeting(name) { alert('Hello ' + name); } function processUserInput(callback) { var name = prompt('Please enter your name.'); callback(name); } processUserInput(greeting);
-
Call by value vs. call by reference
Javascript always passes by value. However, if you pass an object to a function, the "value" is really a reference to that object, so the function can modify that object's properties but not cause the variable outside the function to point to some other object.
-
newoperator:-
The new operator creates an instance of a user-defined object type or of one of the built-in object types that has a constructor function. The new keyword does the following 4 things:
- It creates a brand new object out of thin air.
- It links this object to another object.
- The newly created object from Step 1 gets passed as the this context.
- If the function doesn't return it's own object, this is returned.
function Car(make, model, year) { this.make = make; this.model = model; this.year = year; } var car1 = new Car('Eagle', 'Talon TSi', 1993); console.log(car1.make); // expected output: "Eagle"
Source: MDN new operator
-
Temporary merge branch 2
if (condition1) {
//when condition1 is true this will be executed
} else if (condition2) {
//if condition1 is false and condition2 is true this will be executed is true
} else {
//this will be executed if condition1 and condition2 are false
} let name = 'peter';
if (name === 'max') {
console.log('If was true')
} else if (name === 'peter') {
console.log('Else if was true')
} else {
console.log('Else was true')
} Else if was trueswitch (ValueToSwitch) {
case firstValueToCompare:
//This will run if ValueToSwitch == firstValueToCompare
break;
case secondValueToCompare:
//This will run if ValueToSwitch == secondValueToCompare
break;
} let day = ""
switch ("Peter Parker") {
case 0:
day = "Monday";
break;
case 1:
day = "Tuesday";
break;
case 2:
day = "Wednesday";
break;
case 3:
day = "Thursday";
break;
case 4:
day = "Friday";
break;
case 5:
day = "Saturday";
break;
case 6:
day = "Sunday";
break;
default:
day = "This is not a week day"
}
console.log(day) This is not a week daylet i;
for (i = 0; i < Array.length; i++) {
//This will run while i is smaller then the Array
//With each iteration i will increase by one
}let text = ""
for (let i = 0; i < 5; i++) {
text += "The number is " + i + "\n";
}
console.log(text) The number is 0
The number is 1
The number is 2
The number is 3
The number is 4while (condition) {
//the code while run while condition is true
//The check runs before the first iteration
}do {
//the code while run while condition is true
//The check runs after the first iteration
}
while (condition);let i = 0;
let text = "";
while (i < 10) {
text += "The number is " + i + "\n";
i++;
}
console.log(text) The number is 0
The number is 1
The number is 2
The number is 3
The number is 4
The number is 5
The number is 6
The number is 7
The number is 8
The number is 9