questions Flashcards

1
Q

What kinds of approaches do you know to determine type in js?

A

typeof is good for primitives for example number returns number, boolean returns boolean, undefined returns undefined, function returns function . But null returns object.
objects, arrays, dates all return object.
There a special way for Arrays -
Array.isArray (name) - boolean.
In the old days, there was a less secure and less accurate way Duck Typing it`s just a test to find if the variable has property or method which belongs to some particular data structures for example Array.slice

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
2
Q

What is the difference between variable hoisting and function declaration hoisting?

A

Function hoisting is happening together with its body. For variables, it`s just a name.

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
3
Q

How can we create an object in js?

A
  • just with {} - creates a regular object
  • Object.create() - method creates a new object, using an existing object as the prototype
  • new operator - creates a new object, from function constructor or new class.
How well did you know this?
1
Not at all
2
3
4
5
Perfectly
4
Q

What is an object descriptor? What kinds of descriptor properties do you know?

A

Descriptor is an object that describes property behavior. We can use Object.defineProperty() method for that. this method can define a new property directly on an object, or modify an existing property on an object, and return the object. I haven’t used it yet in my practice.
configurable - boolean. Property descriptor may be changed and if the property may be deleted.
enumerable - boolean. If this property shows up during enumeration
value - Can be any valid JavaScript value (number, object, function, etc)
writable - boolean. Can the property be changed or not
get - function where you can create a custom logic how and what will be returned when someone will try to get value of this property.
set - function where you can create a custom logic how and what will be stored for that property.

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
5
Q
Explain how prototypal inheritance works.
How to implement class inheritance in js? Could you provide an example?
A
inheritance in JS is a process when a child class inheritance features from a parent class.
We can implement it by using the keyword "extends".
class A {
  constractor(name) {
     this.name = name;
  }
  say( ) {
     console.log(this.name);
  }
}
class B extends A {
   walk( ) {
       ......
    }
}

const bubka = new B(“Bubka”);

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
6
Q

What will happen when we return an object or a primitive value from a constructor function?

A

It should return the Context by default when we are using a “new” keyword

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
7
Q

What kinds of other strategies except inheritance do you know to implement reusing of the code?

A

By using Context (“this”) methods.
Call, Apply or Bind

Inheritance

extend

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
8
Q

What does the “new” keyword do? prototype vs __proto__ vs [[Prototype]]?

A

it can:

  • Creates a blank, plain JavaScript object.
  • Adds __proto__ property which links to the constructor function’s prototype.
  • Binds methods from the constructor functions prototype to the newly created object.
  • Returns the newly created object.
How well did you know this?
1
Not at all
2
3
4
5
Perfectly
9
Q

What is an “array” in javascript? What is the best way to clone an array?

A

Array is an object that stores values inside. One Array can store values of different types for example string, number, and boolean can be stored in one Array.
You can clone it by using:
.slice() - method returns a copy of a portion of an array into a new array.
.concat() - method is used to merge two or more arrays.Creates a new Array.
Array.from() - static method creates a new, copied Array instance from an array-like.

How well did you know this?
1
Not at all
2
3
4
5
Perfectly