Posts

Showing posts from March, 2024

Successive Interview

Image
 // const a=5; // const b= new Number(5); // console.log(a===b); // setTimeout(() => { console.log("A") }, 1000); // setTimeout(() => { console.log("B") }, 0); // Promise.resolve().then(console.log("C")); // Promise.resolve().then(setTimeout(() => { console.log("D") }, 0)); // console.log("E") // setTimeout(() => { console.log("F") }, 1000); // 'E // 'c' // 'D' // 'B' // 'A' // 'F' // const obj1={ //   name:'Ankit', // printName:function(state){ //   console.log(this.name+state) // }  // } // const obj={ //   name:'tyagi' // } // obj1.printName.call(obj,[''])  var a=[1,0,1,0,0,0,1,0,1,1,0,1,1] // count 0's and 1's // output: { '0': 6, '1': 7 } let map={}; for(let ele of a){      if(map[ele] !==undefined){     map[ele] +=1;   }   else{     map[ele]=1   }    } console.log(map) let ele=10; function outer(){   return ()=>{   ...

Piyush Garg Content

 Lazy Loading and code splitting
 const [val, setVal]=useState("some"); const change=()=>{ setVal(5); add(); } const add=()=>{ console.log(val); } export default function App() {   const [emp, setEmp] = useState({ name: "A", age: 5 });   const update = () => {     emp.age = 10;     console.log()     setEmp(emp);   };   return (     <div className="App">       <h1>Hello CodeSandbox</h1>       <h2>{`${emp.name} : ${emp.age}`}</h2>       <button onClick={update}>Update</button>     </div>   ); } import { useState } from " react " ; const App = () => {   const [ user , setUser ] = useState ({ firstName : "" , lastName : "" }) ;   const updateUser = ( first , last ) => {     setUser ({ ... user , firstName : first }) ;     if ( last ) {       updateLastName ( la...