Senior Front end Interview questions you may fail


What are 3 main components of typescript?
A large feline inhabiting Bodmin Moor.
Object Oriented Programming with TypeScript
Encapsulation. The implementation and state of each object are privately held inside a defined boundary, or class. Other objects do not have access to this class or the authority to make changes but are only able to call a list of public functions, or methods. This characteristic of data hiding provides greater program security and avoids unintended data corruption.

Abstraction.

Objects only reveal internal mechanisms that are relevant for the use of other objects, hiding any unnecessary implementation code. This concept helps developers more easily make changes and additions over time.

Inheritance.

Relationships and subclasses between objects can be assigned, allowing developers to reuse a common logic while still maintaining a unique hierarchy. This property of OOP forces a more thorough data analysis, reduces development time and ensures a higher level of accuracy.

Polymorphism.

Objects can take on more than one form depending on the context. The program will determine which meaning or usage is necessary for each execution of that object, cutting down the need to duplicate code.

What are TypeScript Getters and Setters
A getter method returns the value of the property’s value. A getter is also called an accessor.
A setter method updates the property’s value. A setter is also known as a mutator.

As you can see from the code, the setters are useful when you want to validate the data before assigning it to the properties. In addition, you can perform complex logic.

The following shows how to create the fullname getter and setter.


class Person {
// ... other code
public get fullName() {
return `${this.firstName} ${this.lastName}`;
}


public set fullName(name: string) {
let parts = name.split(' ');
if (parts.length != 2) {
throw new Error('Invalid name format: first last');
}
this.firstName = parts[0];
this.lastName = parts[1];
}
}

Principles of Functional Programming

1. Pure functions: 
– Given the same inputs, always returns the same output
– Has no side-effects

2. Immutability
3. Referential transparency
– Referential transparency is a fancy way of saying that if you were to replace a function call with its return value, the behaviour of the programme would be as predictable as before.
4. Functions as first-class entities
– This just means that functions are able to be passed as arguments to other functions, returned as values from other functions, stored in data structures and assigned to variables.
5.Higher order functions
– Takes one or more functions as arguments
– Returns a function as its result

Paterns:
Factory patter –  deal with the problem of creating objects without having to specify the exact class of the object that will be created

// Empty vocabulary of actual object
public interface IPerson
{
string GetName();
}

public class Villager : IPerson
{
public string GetName()
{
return "Village Person";
}
}

public class CityPerson : IPerson
{
public string GetName()
{
return "City Person";
}
}

public enum PersonType
{
Rural,
Urban
}

///

/// Implementation of Factory - Used to create objects.
///

public class Factory
{
public IPerson GetPerson(PersonType type)
{
switch (type)
{
case PersonType.Rural:
return new Villager();
case PersonType.Urban:
return new CityPerson();
default:
throw new NotSupportedException();
}
}
}


One response to “Senior Front end Interview questions you may fail”

  1. Higher order functions:

    `
    const greet = function(name){
    return function(m){

    console.log(`Hi!! ${name}, ${m}`);
    }
    }

    const greet_message = greet(‘ABC’);
    greet_message(“Welcome To GeeksForGeeks”)
    `

Leave a Reply

Your email address will not be published.

This site uses Akismet to reduce spam. Learn how your comment data is processed.