questions 3 Flashcards
what is DOM
The Document Object Model (DOM) is a programming interface for web documents. It represents the page so that programs can change the document structure, style, and content. As an object-oriented representation of the web page, it can be modified with a scripting language such as JavaScript.
Function expression/IIF(Immediately Invoked Function Expression)
The unnamed Immediately Invoked Function Expression. The pattern that lets you call the function along with the declaration.
IIF- (function () {
……
}) ( );
types in js
Primitive values: Boolean type Null type Undefined type Number type BigInt type String type Symbol type
Spread operator
Works just with functions call to spread Arrays values to parameters. [1,2,3] -> 1,2,3 a = [1,2,3] func1(...a) function func1(a1,a2,a3) { // a1 = 1, a2 = 2, a3 = 3 }
Rest operator
Works just with function declarations, tern parameters to Arrays. 1,2,3 -> [1,2,3] function func2(...restParams) { // restParams.= [1,2,3] } func2(1,2,3)
Object Destructuring
Pull out needed properties as variables from object. a = { a1:1, a2:2, a3:3, a4:4, a5:5 }
const {a2,a3} = a; //a2 = 2, a3 = 3
const {a2, a3, …name} = a; -> create variables a2 and a3 and the rest will be putted to the new object.
Promise
The promise is a mechanism to work with async operations. It has the method “then” which allows us to work with the result of successful async operations or with the error of failed async operations.
“then” returns another promise object so it can be chainable.
Promise has catch method which catches error of failed async operation. catch is a final method you can use in Promise chain
Callback function
lback function is a function passed into another function as an argument
Array Destructuring
Pull out Array values as variables. Each variable will get a value according to its position in an Array.
a = [1,2,3,4,5,6];
const [b, c] = a; // b = 1; c = 2;
const [b, c, , ...rest] = a //b = 1; c = 2; _ = no 3; rest[4,5,6];
Array Destructuring
Pull out Array values as variables. Each variable will get a value according to its position in an Array.
a = [1,2,3,4,5,6];
const [b, c] = a; // b = 1; c = 2;
const [b, c, , ...rest] = a //b = 1; c = 2; _ = no 3; rest[4,5,6];
create Objects with Constructor Function
In JavaScript, you can create multiple objects from a constructor function. To create an object from a constructor function, we use the new keyword.
Each object created from the constructor function is unique. You can have the same properties as the constructor function or add a new property to one particular object. You can add properties or methods in an object later as well.
// constructor function function Person () { this.name = 'John', this.age = 23 }
// create an object const person = new Person();
function Person (person_name, person_age, person_gender) {
// assigning parameter values to the calling object
this. name = person_name, this. age = person_age, this. gender = person_gender, this.greet = function () { return ('Hi' + ' ' + this.name); } }
// creating objects const person1 = new Person('John', 23, 'male'); const person2 = new Person('Sam', 25, 'female');
// accessing properties
console. log(person1.name); // “John”
console. log(person2.name); // “Sam”
// constructor function function Person () { this.name = 'John', this.age = 23 }
// creating objects let person1 = new Person(); let person2 = new Person();
// adding property to person1 object person1.gender = 'male';
// adding method to person1 object person1.greet = function () { console.log('hello'); }