Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- # JavaScript Track Technical Questionnaire
- ## Most Important Questions
- ---
- ### JavaScript Core
- - Какво е **JavaScript**?
- - **JavaScript** е слабо типизиран, прототипно базиран,
- мултипарадигмов програмен език с функции от първи клас.
- - Подходящ е за писане на **web**, **mobile**, и **desktop** апликации.
- - На повърхността си изглежда като интерпретативен език за програмиране,
- но в действителност e **just-in-time compiled** език за програмиране
- - Стандарта за **JavaScript** се нарича **ECMAScript**.
- - Какво е **nodejs**?
- - **node.js** е **open source** платформа за **development**, която ни позволява да
- изпълняваме **JavaScript** код **server-side**
- - базиран е на **Google's V8 engine**
- - Каква е разликата между **var**, **let** и **const**?
- - С ключовите думи **var**, **let** и **const** декларираме (създаваме) променливи.
- - **var**: няма **block scoping**, има **function scoping**, стоността на променливата може да бъде **re-assigned**
- - **let**: има **block scoping**, има **function scoping**, стоността на променливата може да бъде **re-assigned**
- - **const**: има **block scoping**, има **function scoping**, стоността на променливата **НЕ** може да бъде **re-assigned**
- ``` js
- const adult = true;
- if (adult) {
- var name = "Niki";
- let age = 27;
- console.log(age); // 27
- age = 28;
- console.log(age); // 28
- adult = false; // Error!
- }
- console.log(name); // Niki
- console.log(age); // Error!
- ```
- - Каква е разликата между **function declaration**, **function expression** и **arrow function**?
- - **function declaration** трябва да има име
- ```js
- function helloWorld () {
- console.log('Hello World!');
- }
- ```
- - **function expression** трябва да се присвои към променлива
- ```js
- const helloWorld = function () {
- console.log('Hello World!');
- }
- ```
- - **arrow function** няма **arguments object** и няма собствен **this context**
- ```js
- const helloWorld = () => {
- console.log('Hello World!');
- }
- ```
- - Какво е **scope**? Какво е **closure**?
- - **scope** е набор от правила за това как можем да достъпваме променливите с тяхното име
- ```js
- function foo(a) {
- console.log(a); // 2
- }
- foo(2);
- ```
- > **How it is done?**
- **1.** Engine ask for foo
- **2.** Scope finds it in the global scope
- **3.** Engine executes foo()
- **4.** Engine asks for a
- **5.** Scope finds it in the function scope
- **6.** The same happens with console and its method log. Scope finds them and pass them to the engine to use
- - **nested scope** (често имаме повече от един **scope**)
- ```js
- function foo(a) {
- console.log(a + b);
- }
- var b = 2;
- foo( 2 );
- ```
- > **The steps of the previous slide are the same**
- **1.** Engine asks the Scope of foo() (functional scope) for the variable b. But there is no b here.
- **2.** Ok. What about the outside Scope (global scope in this case). Yes there is variable b here.
- - **scope rules:**
- - **Engine** starts at the currently **executing scope** (looks for the variable there)
- - If **the variable** is **not found** keeps going one level up and so on…
- - If the outermost **global scope** is reached the search stops, whether it finds the variable or not.
- - **errors**
- - Reference error
- - When the variable is failed to be found nowhere in the Scopes
- - Type error
- - When the search for the variable is successful but you try to do an illegal action with it
- - **lexical scope**
- - where variables and blocks of scope are authored
- - by you, at write time
- ```js
- function foo (a) {
- var b = a * 2;
- function bar (c) {
- console.log(c, b, a);
- }
- bar(b * 3);
- }
- foo(2);
- ```
- > **How it is done?**
- **1.** Engine executes console.log
- **2.** It needs three variables a, b and c
- **3.** It searches the current scope for c
- **4.** It finds c in the function scope of bar()
- **5.** It searches the current scope for b but there is no such a variable
- **6.** It goes one level up and searches b in the function scope of foo()
- **7.** It finds b in the function scope of foo()
- **8.** The same is steps for b are repeated for a
- - Какво е **Module**? Защо използваме **Modules**?
- - Модул е малка единица код която можем да преизползваме.
- - Модулите са лесни за използване и създават енкапсулация за нашия код.
- - Модулите ни дават по-добра организация на кода и с тяхна помощ избягваме замърсяването на глобалния скоуп.
- - Какво е **this context**?
- - ключовата дума **this** реферира към обекта от където дадена функция е била извикана.
- > в долния пример **this** ще реферира към обекта person и съответно **this.name** ще бъде 'Maria'
- ```js
- const person = {
- name: 'Maria',
- age: 25,
- sayHello: function() {
- console.log(`Hello, I'm ${this.name}`);
- },
- };
- person.sayHello();
- ```
- - **Map**, **Filter** и **Reduce**.
- - **map**, **filter** и **reduce** са **Higher Order Functions** (приемат функция като параметър)
- - те не мутират оригиналния масив, вместо това връшат нова масив.
- - **map()**
- - създава нов масив използвайки стойностите на друг масив (без да променя оригиналния масив)
- ```js
- const people = [
- {name: 'John', age: 20},
- {name: 'Mike', age: 16},
- {name: 'Jenny', age: 22},
- ];
- const peopleAgePlus10 = people.map((person) => {
- person.age += 10;
- return person;
- });
- // [ { name: 'John', age: 30 },
- // { name: 'Mike', age: 26 },
- // { name: 'Jenny', age: 32 } ]
- ```
- - **filter()**
- - Създава нов масив базиран на това дали елементите на даден масив отговарят на дадено условие (предикат)
- ```js
- const people = [
- {name: 'John', age: 20},
- {name: 'Mike', age: 16},
- {name: 'Jenny', age: 22},
- ];
- const peopleLegalAge = people.filter((person) =>
- person.age >= 18
- );
- // [ { name: 'John', age: 20 },
- // { name: 'Jenny', age: 22 } ]
- ```
- - **reduce()**
- - използва акумолатор за да редуцира всички стойности от даден масив до една стойност.
- - резултата от редуцирането може да бъде от всякакъв тип (**array**, **object**, **boolean**, etc.)
- ```js
- const people = [
- {name: 'John', age: 20},
- {name: 'Mike', age: 16},
- {name: 'Jenny', age: 22},
- ];
- const totalAge = people.reduce((accumolator, person) => {
- accumolator += person.age;
- return accumolator;
- }, 0);
- // totalAge 58
- ```
Add Comment
Please, Sign In to add comment