[go: up one dir, main page]

0% found this document useful (0 votes)
6 views8 pages

js - all

The document outlines various JavaScript concepts, coding challenges, and best practices, including topics like the event loop, closures, inheritance, and promises. It also covers TypeScript features, React JS mechanisms, and CSS flexbox properties. Additionally, it provides coding exercises and examples related to array manipulation and API requests, along with testing frameworks like Jest.

Uploaded by

michaelscf107
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as DOCX, PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
6 views8 pages

js - all

The document outlines various JavaScript concepts, coding challenges, and best practices, including topics like the event loop, closures, inheritance, and promises. It also covers TypeScript features, React JS mechanisms, and CSS flexbox properties. Additionally, it provides coding exercises and examples related to array manipulation and API requests, along with testing frameworks like Jest.

Uploaded by

michaelscf107
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as DOCX, PDF, TXT or read online on Scribd
You are on page 1/ 8

Questions:

JavaScript:

1. Event loop,
2. call,apply,bind, -> bind*,
3. closers & disadvantages of using closures
4. hoisting,
5. .this,
6. arrow function,
7. spread operator, set, rest, reduce
8. array helper function => filter, map, foreach -> diff & return
9. Inheritance -> Class & Prototypal Inheritance,
10. Class & function, -> es6
11. import & export VS required,
12. function currying,
13. promises VS async await -> difference
14. Callback
15. pure function,
16. event bubbling,
17. event target,
18. deep copy & shall copy,
19. DE structuring
20. IIF -> self invoking
21. polyfill for .bind
22. design pattern *
23. seo
24. memory leaks
25. HOC
26. Event listener
27. Temp var with eg

Common:

 Authentication implementation, *
 Performance testing, *
 Security,
 Application Performance improvement
 webpack
 package json -> dependence
 best way to iterate large json value eg:pagination, lazy loading *
 sso
 shared component
 how we go with component structure .. eg: from scratch …
 cookies, session, local storage
JavaScript Coding:

1. sum of numbers
o eg: const a = [10,30,40,10,60] sum=50.
o With single iteration
2. Sum of number
a. Const a = [10,20,30,[40,50],70] output = total
3. Input = “ababbccdd” output=“2a3b2c2d”
4. Array find largest and second largest eg: const a = [10,30,40,60,70,90,40];
5. Input=5, output = [1,1,2,3,5,8]
6. Find prime number
7. swap -> temp
8. for(let i=0;i<10;i++){ setTimeout(() => {console.log(i);},100);}
9.

class example { this.logoutput() }

logoutput() {console.log('button')}

render() {return (<button onClick={ logoutput } />)

10.console.log(1) setTimeout(() => {console.log(2);},100); console.log(3) => need to execute in same

11.

const Avengers = [

fname: "tony",

lname: "stark",

age: 30,

gender: "M",

powers: ["inteligence", "money"]

},

fname: "natasha",

lname: "romonov",

age: 23,
gender: "M",

powers: ["inteligence", "slow ageing"]

];

function Select(string,arr){

let input = string.split(",");

let arrResult = [];

for(let val of arr){

let obj = {};

for(let i=0;i<input.length;i++){

let currentVal = input[i];

obj[currentVal] = val[currentVal];

arrResult.push(obj);

return arrResult;

const list2 = Select("fname,lname,gender", Avengers);

console.log(list2);

for in, for of,


10. (null === null) (obj===obj) *
11. Add(a)(b) =>

multiple API requests in parallel


 Promises all => all must get resolved, if any one got rejected all will reject
 let [someResult, anotherResult] = await Promise.all([someCall(), anotherCall()]);
 if we want to show the resolved(eg: 1 api got reject) we r using =>
 await Promise.allSettled([someCall(), anotherCall()]);
https://levelup.gitconnected.com/combining-api-calls-with-javascript-try-catch-ba1b7b9303a5 in asyn
await only

*TypeScript is a super set of JavaScript.


*In TypeScript, an interface is an abstract type that tells the compiler which property names
a given object can have.
*TypeScript creates implicit interfaces when you define an object with properties.

TypeScript is a superset of JavaScript that gives you advantages like: Optional static
typing (the key here is optional) Type Inference,

let n1 = 0, n2 = 1, nextTerm;
let number = 10;
let arr = [];
for (let i = 0; i < number; i++) {
arr.push(n1);
nextTerm = n1 + n2;
n1 = n2;
n2 = nextTerm;
}
console.log(arr);

10) [0, 1, 1, 2, 3, 5, 8, 13, 21, 34] let a = 10;


let b = 20;
let temp;
temp = a;
a = b;
b = temp;

or

[a,b] = [b,a]

React JS:

 Mechanism behind virtual dom,

HTML:

Div hight

Css:

 flex-direction
 flex-wrap
 flex-flow
 justify-content
 align-items
 align-content

Testcase:

describe('CrashRiskGridComponent', () => {
let component: CrashRiskGridComponent;
let fixture: ComponentFixture<CrashRiskGridComponent>;
let crashRiskGridService: CrashPreventionService;
beforeEach(() => {
const mockStateAdapter = createSpyFromClass(StateAdapter, {

TestBed.configureTestingModule({
imports: [
CrashRiskGridModule,
HttpClientTestingModule,
RouterTestingModule,
OktaAuthServiceTestModule,
],
providers: [
{ provide: 'ENVIRONMENT', useValue: {} },
provideMockStore({
selectors: [
{
selector: userStateSelectors.selectUserState,
crashRiskGridService = TestBed.inject(CrashPreventionService);
fixture = TestBed.createComponent(CrashRiskGridComponent);
component = fixture.componentInstance;
fixture.detectChanges();

jest
.spyOn(crashRiskGridService, 'findRiskDevices')

.mockReturnValue(of(RiskScenarios[4].scenarios.GET[0].response.body));

JS:

1.generatore(elead) -> pass and paly

2. rest vs spread

3.setTimeout()

4.
https://www.programiz.com/javascript/setInterval

let chars = ['a','c','d','e','f','a','g','d']

console.log(chars.filter((chr,index)=>chars.indexOf(chr)===index)

off => it return value

in => it return index

var data = [{

"name": "Peter",

"age": 30,

"hair color": "brown"

}, {

"name": "Steve",

"age": 55,

"hair color": "blonde"

}, {

"name": "Steve",

"age": 55,

"hair color": "blonde"

}];

//console.log(JSON.stringify(data));

let distinctList = [];

for(let obj of data){

if(!distinctList.length || ((JSON.stringify(distinctList)).indexOf(JSON.stringify(obj))==-1))

distinctList.push(obj);
}

console.log(distinctList);

find first and second

let arr = [1,2,3,8,6,7];

let largest=0;
let second = 0;
for(let i=0;i<=arr.length;i++){
if(arr[i]>largest){
second = largest;
largest = arr[i];
}else if(arr[i] > second && arr[i] != largest ){
second = arr[i];
}
}

console.log(second);

You might also like