interview questions js[ Anurag Singh ProCodrr]

 javascript:-

nderstanding-the-difference-between-pure-and-impure-functions-in-javascript/

pure function:-

that does not change outside value of the function

1:

function geek(value) { 

    return value+100; 

  

console.log(geek(34)); 



2:

function capitalize(str) { 

  return str.toUpperCase(); 

  

console.log(capitalize('geeks'));

.............................


lamda function[anonymous function]


doesnt have name

Lambda functions are pure functions in Javascript.

let multiply = (a, b) => a * b;

console.log(multiply(5, 9));

const Names = [

  'Mansi',

  'Gaurav',

  'Akansha',

  'Sanya'

];


console.log(Names.map(Names => Names.length));


 

array.slice[parts the array] gives array returns


The slice() method returns selected elements in an array, as a new array.


The slice() method selects from a given start, up to a (not inclusive) given end.


The slice() method does not change the original array.


const fruits = ["Banana", "Orange", "Lemon", "Apple", "Mango"];

const citrus = fruits.slice(1, 3);


array.splice[replace that element] it modifies

The splice() method adds and/or removes array elements.


The splice() method overwrites the original array.


array.splice(index, count, item1, ....., itemX)


const fruits = ["Banana", "Orange", "Apple", "Mango"];


// At position 2, add "Lemon" and "Kiwi"

fruits.splice(2, 0, "Lemon", "Kiwi");




higher order function:-[concept of closure]

takes a function as an parameter and returns functions

JavaScript Higher-Order Functions are functions that can accept

 other functions as arguments, return functions, or both



prototype:-

[Root]

................


Factory function:--

In JavaScript, a factory function is a function that returns an object.



// Function creating new objects 

// without use of 'new' keyword

function createRobot(name) {

    return {

        name: name,

        talk: function () {

            console.log('My name is '

                + name + ', the robot.');

        }

    };

}

 

//Create a robot with name Chitti

const robo1 = createRobot('Chitti');

 

robo1.talk();

 

 ...................................................................

// Create a robot with name Chitti 2.O Upgraded

const robo2 = createRobot('Chitti 2.O Upgraded');

 

robo2.talk();


constructor function:

Sometimes we need to create many objects of the same type.


To create an object type we use an object constructor function.

// Constructor Function for Person objects

function Person(first, last, age, eye) {

  this.firstName = first;

  this.lastName = last;

  this.age = age;

  this.eyeColor = eye;

}


// Create a Person object

const myFather = new Person("John", "Doe", 50, "blue");


// Display age

document.getElementById("demo").innerHTML =

"My father is " + myFather.age + "."; 

....prototype...to add methods

...................................................

type of class:--function



......................................................................

practicle:--

1:-----

let array=[1,2,3,4];

array.length=0;

console.log(array);//empty

2:--------------

Object.preventExtensions() allows modifications, but prevents addition of properties.


Object.seal() allows modifications, but prevents additions and deletions of properties.


Object.freeze() prevents modifications, additions and deletions of properties.


Object.defineProperty(obj, "uuid", { configurable: false, writable: false });



Debouncing: Debouncing is a technique where you delay the execution of a function until after a certain amount of time has

 passed. This is useful if you have a frequently used function—say, a scroll or

 resize event listener—and don’t want to trigger it too frequently because that might slow down the browser.



Throttling is a similar technique to debouncing, but instead of delaying the execution of a function,

 it limits the rate at which a function. This is useful when a function, such as a mousemove or keydown event listener,

 may be called repeatedly but need not be run each time.

Throttling is a technique in which, no matter how many times 

the user fires the event, the attached function will be executed only once in a given time interval. 

Throttling ensures that the function executes at regular intervals.



output:--

function foo(a,...rest,c){

console.log(a,rest,c);


}

we can not write a variable after rest operator will give u syntax error...




............................................................................................

frontend interview:---

The typeof operator:- returns the type of a variable or an expression.

JavaScript has 7 primitive data types:

string

number

boolean

bigint

symbol

null

undefined


JavaScript is mainly interpreted, but modern JavaScript engines, like V8 in Google Chrome, use JIT (Just-In-Time) compilation to boost performance.

 They convert JavaScript code into optimized machine code right before it runs.

 This mix of interpretation and JIT compilation makes JavaScript fast and versatile for web applications.



 In simple terms, the lexical scope is the scope of a variable or function based on where it is defined in the source code. 




block the browser by using loop or date object only.


typeof abcd:--undefined


console.log(abcd):error


reference error:--

console.log(typeof a);//temporal dead zone

let a;



destructuring:--

const [a,,b]=[1,2,3,4];

log a,b:-1,3


object destructuring on array:---

const {4:b}=[1,2,3,4,5]

will access 5


web interview:-----

.......................................................................................................................................

sementic element

alt attribute :accessibility SEO screen reader

type attribute ol


:-svg and canvas

:inline element we can not give hight and width.


cascading 

style sheet


overwritten with bottom css..

specificy:--id and class id specify id

class specificity

p  id=head

#heading{


}

p#heading

{


}

priority:--------------

pseudo class

What are Pseudo-classes?

A pseudo-class is used to define a special state of an element.


For example, it can be used to:


Style an element when a user mouses over it

Style visited and unvisited links differently

Style an element when it gets focus

...........

What are Pseudo-Elements?

A CSS pseudo-element is used to style specified parts of an element.


For example, it can be used to:


Style the first letter, or line, of an element

Insert content before, or after, the content of an element

The ::first-line Pseudo-element

The ::first-line pseudo-element is used to add a special style to the first line of a text.


The following example formats the first line of the text in all <p> elements:


Example 

p::first-line {

  color: #ff0000;

  font-variant: small-caps;

}


selectors css:----

..........................................

:--typeof typeof a;

:--string:

difference:---

ternary is expression 

if else is a statement


type conversion:--

explicit conversion

"12"-2=10 implicit converion 

what is scope in js.

global scope

block scope

function scope

lexical scope


.......................................

output:--

1<2left shift

3>2right shift

......................................................................


javascript interview:--------

position default value

absolute and relative property diff

em:-

parent tag:--



html{

fontSize:16px;

}


rem:relative parent

em and rem:--

box sizing:border box content box


combinator selector > +


dynamically typed language












Comments

Popular posts from this blog

reactnative_creation