interface and type
Function overlaoading
OOPS Concept
Anonymous
undefined error
decode and encode URI
escape and un escape function'
unshift position in Java script
Screen Obects in Java Script
Event handlers in Java Script
Event bubbling
Redux v/s Flux
Components of Redux
What is redux
Role of reducer
Fragment - what is the signifance
Higher order Compoenent
Pure compoenent
Mounting, Unmount, Constructor
Render method on React
When it is invoked .. what result will it give - render
state and stateless components
Redux - what is it ?
Flux
Higher Order components
Control and Uncontrolled compoenents - Prop and States
Lifecycle
Java Script ----
Not Advised to use inner HTML - Why ?
Unshift Method - Explain
Screen Objects - Explain
Event Bubbling in Javascript
Method Overriding
-generics in type script
- write code to print prime number 2- 20

***************************************************************
L2

class components and functional components and hooks
How it helps - to use above which is better
Paradigm shift - Difference between OOP v/s Procedure approach - What is intentions of using hooks, what is difference
Styling - Style component as a pattern
how do you style react component.

Style vs/ normal component - difference

React 15 - what is purpose of context

React 16 - context api and state management

what is prop drilling ?

Functional componet - 10 props
1st child - 5 props and rest 5 props will still pass - not used , will it effect rendering


Few more L2 questions

Why react has introduced hooks and what impact new hooks related features are making ?

Why we should not doing prop drilling and use react' context API?

Different between functional components and classs components?

How react diffing algo works?

And one practical example of search input and dropdown in react

******************************************************************************

class components and functional components and hooks
How it helps - to use above which is
better
Paradigm shift - Difference between OOP v/s Procedure approach - What is intentions of using hooks, what is difference
Styling - Style component as a pattern
how do you style react component.

Style vs/ normal component - difference

React 15 - what is purpose of context

React 16 - context api and state management

what is prop drilling ?

Functional componet - 10 props



*******************************************************************************************
One more input
Design a simple page with a textbook where there are some autocomplete suggestions, with some styling **************************************************************************************************
React state management
2.How it works in react js
3.Why we use React Hooks
4.Difference between React hook cycle of Class vs Functional components
5.How the states work in class as well functional components
6.Design Search box with auto suggestion box using json data --- Online Test

Autocomplete allows the browser to predict the value. When a user starts to type in a field, the browser should display options to fill in the field, based on earlier typed values.

AutoFocus The autofocus attribute is a boolean attribute.

When present, it specifies that an <input> element should automatically get focus when the page loads.

required The required attribute is a boolean attribute.

When present, it specifies that an input field must be filled out before submitting the form.

URL — Uniform Resource Locator

HTML URL Encoding Reference

URL Encoding (Percent Encoding)

URLs can only be sent over the Internet using the ASCII character-set.

Since URLs often contain characters outside the ASCII set, the URL has to be converted into a valid ASCII format.

URL encoding replaces unsafe ASCII characters with a “%” followed by two hexadecimal digits.

URLs cannot contain spaces. URL encoding normally replaces a space with a plus (+) sign or with %20.

URL Encoding Functions

In JavaScript you can use the encodeURIComponent() function.

The decodeURIComponent() function decodes a URI component.

Note: The JavaScript function encodes space as %20.

ASCII Encoding Reference

The default character-set in HTML5 is UTF-8.

Function Overloading

Unlike the other programming languages JavaScript Does not support Function Overloading. but we can implement the function Overloading on our own, which is pretty much complex when it comes to more number and more type of arguments.

In JavaScript if two functions are defined with same name, then the last defined function will overwrite the former function.

// Creating a class "foo"
class foo {
// Creating an overloable method/function.
overloadableFunction() {
// Define three overloaded functions
var function1 = function (arg1) {
console.log("Function1 called with"
+ " arguments : " + arg1);
return arg1;
};
var function2 = function (arg1, arg2) {
console.log("Function2 called with"
+ " arguments : " + arg1
+ " and " + arg2);
return arg1 + arg2;
};
var function3 = function (arg1) {
var concatinated__arguments = " ", temp = " "
// Concatinating all the arguments
// and storing them into a string
for (var i = 0; i < arg1.length; i++) {
concatinated__arguments =
concatinated__arguments + arg1[i]
}
/* Just ignore this loop and temp variable,
we are using this loop to concatinate
arguments with a space between them */
for (var i = 0; i < arg1.length; i++) {
temp = temp + " " + arg1[i]
}
console.log("Function3 called with this"
+ " array as an argument : [" + temp + "]");
console.log("Output of log is : ")
// Returns concatinated argument string
return concatinated__arguments;
};
/* Here with the help of the length of the
arguments and the type of the argument
passed ( in this case an Array ) we
determine which function to be executed */
if (arguments.length === 1
&& Array.isArray(arguments[0])) {
return function3(arguments[0]);
} else if (arguments.length === 2) {
return function2(arguments[0], arguments[1]);
} else if (arguments.length === 1
&& !Array.isArray(arguments[0])) {
return function1(arguments[0]);
}
}
}
// Driver Code// Instantiate an object of the "foo" class
var object = new foo();
// Call the overloaded functions using the
// function overloadableFunction(...)
// We are passing 1 argument so executes function1
console.log(object.overloadableFunction("Geeks"));
// We are passing two arguments so executes function2
console.log(object.overloadableFunction("Geeks", "for"));
// We are passing an array so executes function3
console.log(object.overloadableFunction(
["Geeks", "for", "Geeks"]));

Output:

Function1 called with arguments : Geeks
Geeks
Function2 called with arguments : Geeks and for
Geeksfor
Function3 called with this array as an argument : [ Geeks for Geeks]
GeeksforGeeks
Output of log is :
GeeksforGeeks

Screen Object

availHeight Returns the height of the screen (excluding the Windows Taskbar).

availWidth Returns the width of the screen (excluding the Windows Taskbar).

height Returns the total height of the screen.

width Returns the total width of the screen.

colorDepth Returns the bit depth of the color palette for displaying images.

pixelDepth Returns the color resolution (in bits per pixel) of the screen.

splice function:

Note: This method changes the original array.

arr.splice(index, 0, itemsToadd);

0: items to delete

will insert itemsToadd into arr at the specified index.

var fruits = [“Banana”, “Orange”, “Apple”, “Mango”];
fruits.splice(2, 0, "Lemon", "Kiwi");
fruits.splice(2, 1, "Lemon", "Kiwi");
#Output:
Banana,Orange,Lemon,Kiwi,Apple,Mango
Banana,Orange,Lemon,Kiwi,Mango

slice() method

The slice() method selects the elements starting at the given start argument, and ends at, but does not include, the given end argument.

var fruits = ["Banana", "Orange", "Lemon", "Apple", "Mango"];
var citrus = fruits.slice(1, 3);
#output:
Orange,Lemon

Note: The original array will not be changed.

unshift() Method

In TypeScript, we have a lot of basic types, such as string, boolean, and number. These are the basic types of TypeScript. You can check the list of all the basic types here. Also, in TypeScript, we have advanced types and in these advanced types, we have something called type aliases. With type aliases, we can create a new name for a type but we don’t define a new type.

Interfaces in JS

  1. JavaScript inheritance is based on objects, not classes. That’s not a big deal until you realize:

Types vs. interfaces

Interfaces are basically a way to describe data shapes, for example, an object.

Type is a definition of a type of data, for example, a union, primitive, intersection, tuple, or any other type.

1. Declaration merging

Let’s imagine that we have two interfaces called Song, with different properties:

interface Song {
artistName: string;
};
interface Song {
songName: string;
};
const song: Song = {
artistName: "Freddie",
songName: "The Chain"
};

TypeScript will automatically merge both interfaces declarations into one, so when we use this Song interface, we’ll have both properties.

Declaration merging does NOT work with types. If we try to create two types with the same names, but with different properties, TypeScript would still throw us an error.

Duplicate identifier Song.

2. Extends and implements

for more @https://blog.logrocket.com/types-vs-interfaces-in-typescript/

When a subclass extends a class, it allows the subclass to inherit (reuse) and override code defined in the supertype.

When a class implements an interface, it allows an object created from the class to be used in any context that expects a value of the interface.

Intersection

Unions

Tuples

type Reponse = [string, number]

But, in TypeScript, we can only declare tuples using types and not interfaces. There’s no way we can declare a tuple in TypeScript using an interface, but you still are able to use a tuple inside an interface, like this:

interface Response {
value: [string, number]
}

We can see that we can achieve the same result as using types with interfaces.

interfaces in Typescript

Interfaces define properties, methods, and events, which are the members of the interface. Interfaces contain only the declaration of the members. It is the responsibility of the deriving class to define the members. It often helps in providing a standard structure that the deriving classes would follow.

Let’s consider an object −

var person = { 
FirstName:"Tom",
LastName:"Hanks",
sayHi: ()=>{ return "Hi"}
};

If we consider the signature of the object, it could be −

{ 
FirstName:string,
LastName:string,
sayHi()=>string
}

To reuse the signature across objects we can define it as an interface.

Declaring Interfaces

Syntax

interface interface_name { 
}

Example: Interface and Objects

interface IPerson { 
firstName:string,
lastName:string,
sayHi: ()=>string
}
var customer:IPerson = {
firstName:"Tom",
lastName:"Hanks",
sayHi: ():string =>{return "Hi there"}
}
console.log("Customer Object ")
console.log(customer.firstName)
console.log(customer.lastName)
console.log(customer.sayHi())
var employee:IPerson = {
firstName:"Jim",
lastName:"Blakes",
sayHi: ():string =>{return "Hello!!!"}
}

console.log("Employee Object ")
console.log(employee.firstName);
console.log(employee.lastName);

The example defines an interface. The customer object is of the type IPerson. Hence, it will now be binding on the object to define all properties as specified by the interface.

Another object with following signature, is still considered as IPerson because that object is treated by its size or signature.

How To Use Generics in TypeScript

Introduction

With generics, you can write dynamic and reusable generic blocks of code. Furthermore, you can apply generics in TypeScript to classes, interfaces, and functions.

In this article, you will integrate generics into your TypeScript code and apply them to functions and classes. You will also learn how to add constraints to generics in TypeScript by using interfaces.

Prerequisites

Step 1 — Understanding Generics

// for number type
function fun(args: number): number {
return args;
}
// for string type
function fun(args: string): string {
return args;
}

Note that, in this example, the same function is being repeated for number and string types. Generics can help you to write generalized methods instead of writing and repeating the same block of code, as in the above example.

Alternative: There is a type called any, which you can use to achieve the same effect as generics in your code. Using the any type will allow you to opt-out of type-checking. However, any is NOT type-safe. This means that using any can give you an exception.

To see this in practice, apply the any type to the previous code example:

function fun(args: any): any {
return args;
}

Swapping number and string types to the any type makes the function generic. But there’s a catch—using the any type means that the fun function can accept any data. As a result, you are losing type safety as well.

Although using the any type is a way to make your TypeScript code more generic, it may not always be the best option. In the next step, you explore a different option for creating type-safe generics.

useCases of HOC

showing a loader, while a component waits for data

Over-riding & not Overloading

There is no real function overloading in JavaScript since it allows to pass any number of parameters of any type. You have to check inside the function how many arguments have been passed and what type they are. The correct answer is THERE IS NO OVERLOADING IN JAVASCRIPT.

function foo(arg1) {
console.log(arg1);
}
function foo(arg1, arg2) {
console.log(arg1, arg2);
}
// Driver codefoo("Geeks")

The reason for the “undefined” in the output is: In JavaScript if two functions are defined with same name then the last defined function will overwrite the former function.
So in this case the foo(arg1) was overwritten by foo(arg1,arg2), but we only passed one Argument (“Geeks”) to the function. It means that the second argument is undefined, So when we tried to print the second argument, it is printed as “undefined”.

We have seen that function Overloading is not support in JavaScript, but we can implement the function Overloading on our own, which is pretty much complex when it comes to more number and more type of arguments.

for more @ https://www.geeksforgeeks.org/function-overloading-in-javascript/

Why using innerHTML sometimes is NOT recommended

The use of innerHTML very slow:

The process of using innerHTML is much slower as its contents as slowly built,

also already parsed contents and elements are also re-parsed which takes time.

  • Use innerHTML when you’re setting text inside of an HTML tag like an anchor tag, paragraph tag, span, div, or textarea.
  • Use appendChild() If you’re trying to add new DOM elements inside of another DOM element.

In other words, creating a new element and appending it to the DOM tree provides better performance than the innerHTML.

createElement is more performant

let div = document.querySelector('.container');

let p = document.createElement('p');
p.textContent = 'JS DOM';
div.appendChild(p);

Using DocumentFragment for composing DOM Nodes

let div = document.querySelector('.container');for (let i = 0; i < 1000; i++) {
let p = document.createElement('p');
p.textContent = `Paragraph ${i}`;
div.appendChild(p);
}
Code language: JavaScript (javascript)

This code results in recalculation of styles, painting, and layout every iteration. This is not very efficient.

To overcome this, you typically use a DocumentFragment to compose DOM nodes and append it to the DOM tree:

let div = document.querySelector('.container');// compose DOM nodes
let fragment = document.createDocumentFragment();
for (let i = 0; i < 1000; i++) {
let p = document.createElement('p');
p.textContent = `Paragraph ${i}`;
fragment.appendChild(p);
}
// append the fragment to the DOM tree
div.appendChild(fragment);
Code language: JavaScript (javascript)

In this example, we composed the DOM nodes by using the DocumentFragment object and append the fragment to the active DOM tree once at the end.

A document fragment does not link to the active DOM tree, therefore, it doesn’t incur any performance.

Method Over-riding in TypeScript

  • We use super keyword to refer to the functions or fields of the immediate parent class.

Below is an example of method overriding USING super. If we use super, the same method of parent class is executed.

Below is the output of above code

Below is an example WITHOUT using super. If we skip super, then that method of parent class is NOR executed. Only the method of child class is executed.

Below is the output of above code

Autocomplete feature in React

ABstract Classes

Does a change in props cause re-render?

A re-render can only be triggered if a component’s state has changed. The state can change from a props change, or from a direct setState change.

Experience with Front-end Technologies and MERN / MEAN Stack. Working on all Major UI Frameworks like React, Angular.