├── README.md └── Important Questions ├── contextAPI ├── vite.config.js ├── src │ ├── main.jsx │ ├── App.jsx │ ├── context │ │ └── AppContext.jsx │ ├── App.css │ ├── index.css │ └── assets │ │ └── react.svg ├── .gitignore ├── index.html ├── README.md ├── .eslintrc.cjs ├── package.json └── public │ └── vite.svg ├── reactPractise ├── vite.config.js ├── src │ ├── main.jsx │ ├── App.css │ ├── App.jsx │ ├── index.css │ └── assets │ │ └── react.svg ├── .gitignore ├── index.html ├── .eslintrc.cjs ├── package.json └── public │ └── vite.svg ├── EXTRA_QUESTIONS.md ├── BEHAVIOUR.md ├── PROMISE.md ├── CALLBACK.md ├── OUTPUT_QUESTIONS.md ├── README.md ├── TYPESCRIPT.md ├── POLYFILL.md ├── CODING_QUESTIONS.md ├── htmlPractise.html └── DEV_QUESTIONS.md /README.md: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/Sayan-Maity/Last-Minute-Javascript/HEAD/README.md -------------------------------------------------------------------------------- /Important Questions/contextAPI/vite.config.js: -------------------------------------------------------------------------------- 1 | import { defineConfig } from 'vite' 2 | import react from '@vitejs/plugin-react' 3 | 4 | // https://vitejs.dev/config/ 5 | export default defineConfig({ 6 | plugins: [react()], 7 | }) 8 | -------------------------------------------------------------------------------- /Important Questions/reactPractise/vite.config.js: -------------------------------------------------------------------------------- 1 | import { defineConfig } from 'vite' 2 | import react from '@vitejs/plugin-react' 3 | 4 | // https://vitejs.dev/config/ 5 | export default defineConfig({ 6 | plugins: [react()], 7 | }) 8 | -------------------------------------------------------------------------------- /Important Questions/reactPractise/src/main.jsx: -------------------------------------------------------------------------------- 1 | import React from 'react' 2 | import ReactDOM from 'react-dom/client' 3 | import App from './App.jsx' 4 | import './index.css' 5 | 6 | ReactDOM.createRoot(document.getElementById('root')).render( 7 | 8 | 9 | , 10 | ) 11 | -------------------------------------------------------------------------------- /Important Questions/contextAPI/src/main.jsx: -------------------------------------------------------------------------------- 1 | import ReactDOM from 'react-dom/client' 2 | import App from './App.jsx' 3 | import './index.css' 4 | import { AppProvider } from './context/AppContext.jsx' 5 | 6 | ReactDOM.createRoot(document.getElementById('root')).render( 7 | 8 | 9 | 10 | ) 11 | -------------------------------------------------------------------------------- /Important Questions/contextAPI/.gitignore: -------------------------------------------------------------------------------- 1 | # Logs 2 | logs 3 | *.log 4 | npm-debug.log* 5 | yarn-debug.log* 6 | yarn-error.log* 7 | pnpm-debug.log* 8 | lerna-debug.log* 9 | 10 | node_modules 11 | dist 12 | dist-ssr 13 | *.local 14 | 15 | # Editor directories and files 16 | .vscode/* 17 | !.vscode/extensions.json 18 | .idea 19 | .DS_Store 20 | *.suo 21 | *.ntvs* 22 | *.njsproj 23 | *.sln 24 | *.sw? 25 | -------------------------------------------------------------------------------- /Important Questions/reactPractise/.gitignore: -------------------------------------------------------------------------------- 1 | # Logs 2 | logs 3 | *.log 4 | npm-debug.log* 5 | yarn-debug.log* 6 | yarn-error.log* 7 | pnpm-debug.log* 8 | lerna-debug.log* 9 | 10 | node_modules 11 | dist 12 | dist-ssr 13 | *.local 14 | 15 | # Editor directories and files 16 | .vscode/* 17 | !.vscode/extensions.json 18 | .idea 19 | .DS_Store 20 | *.suo 21 | *.ntvs* 22 | *.njsproj 23 | *.sln 24 | *.sw? 25 | -------------------------------------------------------------------------------- /Important Questions/contextAPI/src/App.jsx: -------------------------------------------------------------------------------- 1 | import { useContext } from 'react' 2 | import './App.css' 3 | import AppContext from './context/AppContext' 4 | 5 | function App() { 6 | const {isOn, handleSwitch} = useContext(AppContext) 7 | return ( 8 | <> 9 | 10 |

Button is switched = {isOn ? 'On' : 'Off'}

11 | 12 | ) 13 | } 14 | 15 | export default App 16 | -------------------------------------------------------------------------------- /Important Questions/contextAPI/index.html: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | 5 | 6 | 7 | Vite + React 8 | 9 | 10 |
11 | 12 | 13 | 14 | -------------------------------------------------------------------------------- /Important Questions/reactPractise/index.html: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | 5 | 6 | 7 | Vite + React 8 | 9 | 10 |
11 | 12 | 13 | 14 | -------------------------------------------------------------------------------- /Important Questions/contextAPI/README.md: -------------------------------------------------------------------------------- 1 | # React + Vite 2 | 3 | This template provides a minimal setup to get React working in Vite with HMR and some ESLint rules. 4 | 5 | Currently, two official plugins are available: 6 | 7 | - [@vitejs/plugin-react](https://github.com/vitejs/vite-plugin-react/blob/main/packages/plugin-react/README.md) uses [Babel](https://babeljs.io/) for Fast Refresh 8 | - [@vitejs/plugin-react-swc](https://github.com/vitejs/vite-plugin-react-swc) uses [SWC](https://swc.rs/) for Fast Refresh 9 | -------------------------------------------------------------------------------- /Important Questions/contextAPI/src/context/AppContext.jsx: -------------------------------------------------------------------------------- 1 | import { createContext, useState } from 'react' 2 | 3 | export const AppContext = createContext() 4 | 5 | export const AppProvider = ({children}) => { 6 | const [isOn, setIsOn] = useState(false) 7 | 8 | const handleSwitch = () => { 9 | setIsOn(!isOn) 10 | } 11 | 12 | return ( 13 | 14 | {children} 15 | 16 | ) 17 | } 18 | 19 | export default AppContext -------------------------------------------------------------------------------- /Important Questions/reactPractise/.eslintrc.cjs: -------------------------------------------------------------------------------- 1 | module.exports = { 2 | env: { browser: true, es2020: true }, 3 | extends: [ 4 | 'eslint:recommended', 5 | 'plugin:react/recommended', 6 | 'plugin:react/jsx-runtime', 7 | 'plugin:react-hooks/recommended', 8 | ], 9 | parserOptions: { ecmaVersion: 'latest', sourceType: 'module' }, 10 | settings: { react: { version: '18.2' } }, 11 | plugins: ['react-refresh'], 12 | rules: { 13 | 'react-refresh/only-export-components': 'warn', 14 | }, 15 | } 16 | -------------------------------------------------------------------------------- /Important Questions/contextAPI/.eslintrc.cjs: -------------------------------------------------------------------------------- 1 | module.exports = { 2 | root: true, 3 | env: { browser: true, es2020: true }, 4 | extends: [ 5 | 'eslint:recommended', 6 | 'plugin:react/recommended', 7 | 'plugin:react/jsx-runtime', 8 | 'plugin:react-hooks/recommended', 9 | ], 10 | ignorePatterns: ['dist', '.eslintrc.cjs'], 11 | parserOptions: { ecmaVersion: 'latest', sourceType: 'module' }, 12 | settings: { react: { version: '18.2' } }, 13 | plugins: ['react-refresh'], 14 | rules: { 15 | 'react/jsx-no-target-blank': 'off', 16 | 'react-refresh/only-export-components': [ 17 | 'warn', 18 | { allowConstantExport: true }, 19 | ], 20 | }, 21 | } 22 | -------------------------------------------------------------------------------- /Important Questions/contextAPI/package.json: -------------------------------------------------------------------------------- 1 | { 2 | "name": "contextapi", 3 | "private": true, 4 | "version": "0.0.0", 5 | "type": "module", 6 | "scripts": { 7 | "dev": "vite", 8 | "build": "vite build", 9 | "lint": "eslint . --ext js,jsx --report-unused-disable-directives --max-warnings 0", 10 | "preview": "vite preview" 11 | }, 12 | "dependencies": { 13 | "react": "^18.2.0", 14 | "react-dom": "^18.2.0" 15 | }, 16 | "devDependencies": { 17 | "@types/react": "^18.2.66", 18 | "@types/react-dom": "^18.2.22", 19 | "@vitejs/plugin-react": "^4.2.1", 20 | "eslint": "^8.57.0", 21 | "eslint-plugin-react": "^7.34.1", 22 | "eslint-plugin-react-hooks": "^4.6.0", 23 | "eslint-plugin-react-refresh": "^0.4.6", 24 | "vite": "^5.2.0" 25 | } 26 | } 27 | -------------------------------------------------------------------------------- /Important Questions/reactPractise/package.json: -------------------------------------------------------------------------------- 1 | { 2 | "name": "reactpractise", 3 | "private": true, 4 | "version": "0.0.0", 5 | "type": "module", 6 | "scripts": { 7 | "dev": "vite", 8 | "build": "vite build", 9 | "lint": "eslint src --ext js,jsx --report-unused-disable-directives --max-warnings 0", 10 | "preview": "vite preview" 11 | }, 12 | "dependencies": { 13 | "react": "^18.2.0", 14 | "react-dom": "^18.2.0" 15 | }, 16 | "devDependencies": { 17 | "@types/react": "^18.0.37", 18 | "@types/react-dom": "^18.0.11", 19 | "@vitejs/plugin-react": "^4.0.0", 20 | "eslint": "^8.38.0", 21 | "eslint-plugin-react": "^7.32.2", 22 | "eslint-plugin-react-hooks": "^4.6.0", 23 | "eslint-plugin-react-refresh": "^0.3.4", 24 | "vite": "^4.3.9" 25 | } 26 | } 27 | -------------------------------------------------------------------------------- /Important Questions/contextAPI/src/App.css: -------------------------------------------------------------------------------- 1 | #root { 2 | max-width: 1280px; 3 | margin: 0 auto; 4 | padding: 2rem; 5 | text-align: center; 6 | } 7 | 8 | .logo { 9 | height: 6em; 10 | padding: 1.5em; 11 | will-change: filter; 12 | transition: filter 300ms; 13 | } 14 | .logo:hover { 15 | filter: drop-shadow(0 0 2em #646cffaa); 16 | } 17 | .logo.react:hover { 18 | filter: drop-shadow(0 0 2em #61dafbaa); 19 | } 20 | 21 | @keyframes logo-spin { 22 | from { 23 | transform: rotate(0deg); 24 | } 25 | to { 26 | transform: rotate(360deg); 27 | } 28 | } 29 | 30 | @media (prefers-reduced-motion: no-preference) { 31 | a:nth-of-type(2) .logo { 32 | animation: logo-spin infinite 20s linear; 33 | } 34 | } 35 | 36 | .card { 37 | padding: 2em; 38 | } 39 | 40 | .read-the-docs { 41 | color: #888; 42 | } 43 | -------------------------------------------------------------------------------- /Important Questions/reactPractise/src/App.css: -------------------------------------------------------------------------------- 1 | #root { 2 | max-width: 1280px; 3 | margin: 0 auto; 4 | padding: 2rem; 5 | text-align: center; 6 | } 7 | 8 | .logo { 9 | height: 6em; 10 | padding: 1.5em; 11 | will-change: filter; 12 | transition: filter 300ms; 13 | } 14 | .logo:hover { 15 | filter: drop-shadow(0 0 2em #646cffaa); 16 | } 17 | .logo.react:hover { 18 | filter: drop-shadow(0 0 2em #61dafbaa); 19 | } 20 | 21 | @keyframes logo-spin { 22 | from { 23 | transform: rotate(0deg); 24 | } 25 | to { 26 | transform: rotate(360deg); 27 | } 28 | } 29 | 30 | @media (prefers-reduced-motion: no-preference) { 31 | a:nth-of-type(2) .logo { 32 | animation: logo-spin infinite 20s linear; 33 | } 34 | } 35 | 36 | .card { 37 | padding: 2em; 38 | } 39 | 40 | .read-the-docs { 41 | color: #888; 42 | } 43 | -------------------------------------------------------------------------------- /Important Questions/EXTRA_QUESTIONS.md: -------------------------------------------------------------------------------- 1 | 📝Questions Asked: 2 | 3 | 📎HTML/CSS 4 | 1) DOM 5 | 2) Relative and Absolute position in css 6 | 3) Ways to center a div 7 | 8 | 📎JavaScript 9 | 1) Explain concept of closure 10 | 2) Describe map() 11 | 3) Difference between Spread and Rest operator 12 | 4) Given an array of strings, convert first letter to uppercase and replace "_" with "-" 13 | 5) Coding questions regarding Scoping 14 | 6) Time Complexity of Objects in JavaScript 15 | 16 | 📎React 17 | 1) How to navigate between pages in React 18 | 2) Difference in authentication and authorization 19 | 3) Difference in hashing and encryption 20 | 4) How to achieve protected routes 21 | 5) What are props 22 | 6) How to make a post request in React hooks 23 | 7) Explain useEffect, ContextAPI 24 | 8) Difference in useReducer and useContext 25 | 9) Given a scenario how to implement it with the help of Redux (redux-toolkit) 26 | 27 | -------------------------------------------------------------------------------- /Important Questions/BEHAVIOUR.md: -------------------------------------------------------------------------------- 1 | # Maintain these Ethics/ Behaviour during Interview 2 | 3 | ## Speak Aloud 4 | - The interviewer need to know what the candidate is thinking and how he/she is approaching the problem. 5 | 6 | ## Clarify the Question 7 | - If you don't understand the question, ask for clarification. It is better to ask for clarification than to make assumptions. 8 | 9 | ## Think Out Loud 10 | - The interviewer needs to know what you are thinking and how you are approaching the problem. If you are silent, the interviewer will not know what you are thinking. 11 | 12 | ## Proficiency in Techstack 13 | - The interviewer is looking for your proficiency in the tech stack you have mentioned in your resume. If you are not proficient in the tech stack, don't mention it in your resume. Also the role you are applying for that particular tech stack or the language you should be proficient in. 14 | 15 | ## Don't ask for Googling 16 | - If you don't know the answer, don't ask for Googling. The technical interview is for to judge your knowledge and not your Googling skills. -------------------------------------------------------------------------------- /Important Questions/reactPractise/src/App.jsx: -------------------------------------------------------------------------------- 1 | import { useState } from 'react' 2 | import reactLogo from './assets/react.svg' 3 | import viteLogo from '/vite.svg' 4 | import './App.css' 5 | 6 | function App() { 7 | const [count, setCount] = useState(0) 8 | 9 | return ( 10 | <> 11 |
12 | 13 | Vite logo 14 | 15 | 16 | React logo 17 | 18 |
19 |

Vite + React

20 |
21 | 24 |

25 | Edit src/App.jsx and save to test HMR 26 |

27 |
28 |

29 | Click on the Vite and React logos to learn more 30 |

31 | 32 | ) 33 | } 34 | 35 | export default App 36 | -------------------------------------------------------------------------------- /Important Questions/contextAPI/public/vite.svg: -------------------------------------------------------------------------------- 1 | -------------------------------------------------------------------------------- /Important Questions/contextAPI/src/index.css: -------------------------------------------------------------------------------- 1 | :root { 2 | font-family: Inter, system-ui, Avenir, Helvetica, Arial, sans-serif; 3 | line-height: 1.5; 4 | font-weight: 400; 5 | 6 | color-scheme: light dark; 7 | color: rgba(255, 255, 255, 0.87); 8 | background-color: #242424; 9 | 10 | font-synthesis: none; 11 | text-rendering: optimizeLegibility; 12 | -webkit-font-smoothing: antialiased; 13 | -moz-osx-font-smoothing: grayscale; 14 | } 15 | 16 | a { 17 | font-weight: 500; 18 | color: #646cff; 19 | text-decoration: inherit; 20 | } 21 | a:hover { 22 | color: #535bf2; 23 | } 24 | 25 | body { 26 | margin: 0; 27 | display: flex; 28 | place-items: center; 29 | min-width: 320px; 30 | min-height: 100vh; 31 | } 32 | 33 | h1 { 34 | font-size: 3.2em; 35 | line-height: 1.1; 36 | } 37 | 38 | button { 39 | border-radius: 8px; 40 | border: 1px solid transparent; 41 | padding: 0.6em 1.2em; 42 | font-size: 1em; 43 | font-weight: 500; 44 | font-family: inherit; 45 | background-color: #1a1a1a; 46 | cursor: pointer; 47 | transition: border-color 0.25s; 48 | } 49 | button:hover { 50 | border-color: #646cff; 51 | } 52 | button:focus, 53 | button:focus-visible { 54 | outline: 4px auto -webkit-focus-ring-color; 55 | } 56 | 57 | @media (prefers-color-scheme: light) { 58 | :root { 59 | color: #213547; 60 | background-color: #ffffff; 61 | } 62 | a:hover { 63 | color: #747bff; 64 | } 65 | button { 66 | background-color: #f9f9f9; 67 | } 68 | } 69 | -------------------------------------------------------------------------------- /Important Questions/reactPractise/public/vite.svg: -------------------------------------------------------------------------------- 1 | -------------------------------------------------------------------------------- /Important Questions/reactPractise/src/index.css: -------------------------------------------------------------------------------- 1 | :root { 2 | font-family: Inter, system-ui, Avenir, Helvetica, Arial, sans-serif; 3 | line-height: 1.5; 4 | font-weight: 400; 5 | 6 | color-scheme: light dark; 7 | color: rgba(255, 255, 255, 0.87); 8 | background-color: #242424; 9 | 10 | font-synthesis: none; 11 | text-rendering: optimizeLegibility; 12 | -webkit-font-smoothing: antialiased; 13 | -moz-osx-font-smoothing: grayscale; 14 | -webkit-text-size-adjust: 100%; 15 | } 16 | 17 | a { 18 | font-weight: 500; 19 | color: #646cff; 20 | text-decoration: inherit; 21 | } 22 | a:hover { 23 | color: #535bf2; 24 | } 25 | 26 | body { 27 | margin: 0; 28 | display: flex; 29 | place-items: center; 30 | min-width: 320px; 31 | min-height: 100vh; 32 | } 33 | 34 | h1 { 35 | font-size: 3.2em; 36 | line-height: 1.1; 37 | } 38 | 39 | button { 40 | border-radius: 8px; 41 | border: 1px solid transparent; 42 | padding: 0.6em 1.2em; 43 | font-size: 1em; 44 | font-weight: 500; 45 | font-family: inherit; 46 | background-color: #1a1a1a; 47 | cursor: pointer; 48 | transition: border-color 0.25s; 49 | } 50 | button:hover { 51 | border-color: #646cff; 52 | } 53 | button:focus, 54 | button:focus-visible { 55 | outline: 4px auto -webkit-focus-ring-color; 56 | } 57 | 58 | @media (prefers-color-scheme: light) { 59 | :root { 60 | color: #213547; 61 | background-color: #ffffff; 62 | } 63 | a:hover { 64 | color: #747bff; 65 | } 66 | button { 67 | background-color: #f9f9f9; 68 | } 69 | } 70 | -------------------------------------------------------------------------------- /Important Questions/PROMISE.md: -------------------------------------------------------------------------------- 1 | ## CALLBACK, PROMISE(then, async, await, try/catch) 2 | 3 | 4 | 5 | ``` 6 | 7 | function a () { 8 | return new Promise ((resolve, reject) => { 9 | console.log("a") 10 | resolve() 11 | }) 12 | 13 | } 14 | function b (cb) { 15 | return new Promise ((resolve, reject) => { 16 | setTimeout(() => { 17 | console.log("b") 18 | resolve() 19 | }, 2000) 20 | }) 21 | } 22 | function c () { 23 | return new Promise ((resolve, reject) => { 24 | console.log("c") 25 | resolve() 26 | }) 27 | } 28 | 29 | /* 30 | -------------- CALLBACK --------------- 31 | a(function () { 32 | b(function() { 33 | c() 34 | }) 35 | }) 36 | 37 | 38 | ---------------- PROMISE(then) -------------------- 39 | a() 40 | .then(b) 41 | .then(c) 42 | .catch((err) => { 43 | console.log("Error =>", err) 44 | }) 45 | 46 | 47 | ------------------- PROMISE(AWAIT) ------------------ 48 | async function getData () { 49 | await a() 50 | await b() 51 | await c() 52 | .catch((err) => { 53 | console.log("Error =>", err) 54 | }) 55 | } 56 | getData() 57 | 58 | */ 59 | ---------------- PROMISE(TRY/CATCH) ----------------- 60 | async function getData () { 61 | try { 62 | await a() 63 | await b() 64 | await c() 65 | } 66 | catch (err) { 67 | console.log("Error =>", err) 68 | } 69 | } 70 | getData() 71 | 72 | 73 | 74 | 75 | 76 | 77 | 78 | 79 | 80 | 81 | 82 | 83 | 84 | 85 | 86 | ``` -------------------------------------------------------------------------------- /Important Questions/CALLBACK.md: -------------------------------------------------------------------------------- 1 | 2 | 3 | ## Example to explain callback 4 | 5 | ``` 6 | 7 | function home (cb) { 8 | console.log("Home Page") 9 | setTimeout(() => { 10 | cb() 11 | }, 1000) 12 | } 13 | 14 | function register (cb) { 15 | console.log("Register Page") 16 | cb() 17 | } 18 | 19 | function login (cb) { 20 | console.log("Login Page") 21 | setTimeout(() => { 22 | cb() 23 | }, 1000) 24 | } 25 | 26 | function dashboard (cb) { 27 | console.log("Welcome to Dashboard") 28 | } 29 | 30 | home(function () { 31 | register(function () { 32 | login(function () { 33 | dashboard() 34 | }) 35 | }) 36 | }) 37 | 38 | ------------------------------------------------------------ 39 | 40 | home(function () { 41 | register(function () { 42 | login(function () { 43 | dashboard() 44 | }) 45 | }) 46 | }) 47 | 48 | ``` 49 | 50 | ``` 51 | 52 | function home () { 53 | return new Promise((resolve, reject) => { 54 | resolve() 55 | console.log("Home") 56 | }) 57 | } 58 | 59 | function register () { 60 | return new Promise((resolve, reject) => { 61 | setTimeout(() => { 62 | resolve() 63 | console.log("register") 64 | }, 1000) 65 | }) 66 | } 67 | 68 | function login () { 69 | return new Promise((resolve, reject) => { 70 | setTimeout(() => { 71 | resolve() 72 | console.log("Login") 73 | }, 1000) 74 | }) 75 | } 76 | 77 | function dashboard () { 78 | return new Promise((resolve, reject) => { 79 | resolve() 80 | console.log("Dashboard") 81 | }) 82 | } 83 | 84 | ------------------------------------------------------------ 85 | 86 | home() 87 | .then(register) 88 | .then(login) 89 | .then(dashboard) 90 | .catch((err) => { 91 | console.log(err) 92 | }) 93 | 94 | --------------------------------------------------------------- 95 | 96 | async function main () { 97 | await home() 98 | await register() 99 | await login() 100 | await dashboard() 101 | } 102 | main() 103 | 104 | ----------------------------------------------------------------- 105 | 106 | async function main () { 107 | try { 108 | await home() 109 | await register() 110 | await login() 111 | await dashboard() 112 | } catch (err) { 113 | console.log(err) 114 | } 115 | } 116 | main() 117 | 118 | 119 | ``` -------------------------------------------------------------------------------- /Important Questions/OUTPUT_QUESTIONS.md: -------------------------------------------------------------------------------- 1 | 2 | ## Output based interview questions : 3 | 4 | (1). 5 | ``` 6 | let x = "5"; 7 | let y = 2; 8 | 9 | console.log(x + y); 10 | console.log(x - y); 11 | ``` 12 | ``` 13 | 52 14 | 3 15 | 16 | In the first console.log, the + operator is used for concatenation. In the second console.log, 17 | the - operator is used for subtraction. Since the first operand is a string, 18 | the - operator will convert the string to a number. 19 | ``` 20 | 21 | (2). 22 | ``` 23 | for (var i = 0; i < 3; i++) { 24 | setTimeout(() => console.log(i), 1); 25 | } 26 | 27 | for (let i = 0; i < 3; i++) { 28 | setTimeout(() => console.log(i), 1); 29 | } 30 | ``` 31 | ``` 32 | 3 3 3 33 | 34 | 0 1 2 35 | 36 | var is global scope. let is block scope. 37 | ``` 38 | 39 | (3). 40 | ``` 41 | function Person(firstName, lastName) { 42 | this.firstName = firstName; 43 | this.lastName = lastName; 44 | } 45 | 46 | const member = new Person('Ayush', 'Verma'); 47 | Person.getFullName = function() { 48 | return `${this.firstName} ${this.lastName}`; 49 | }; 50 | 51 | console.log(member.getFullName()); 52 | ``` 53 | ``` 54 | TypeError 55 | ``` 56 | 57 | (4). 58 | ``` 59 | function Person(firstName, lastName) { 60 | this.firstName = firstName; 61 | this.lastName = lastName; 62 | } 63 | 64 | const ayush = new Person('Ayush', 'Verma'); 65 | const sarah = Person('Sarah', 'Smith'); 66 | 67 | console.log(ayush); 68 | console.log(sarah); 69 | ``` 70 | ``` 71 | Person { firstName: 'Ayush', lastName: 'Verma' } 72 | undefined 73 | 74 | For sarah, we didn't use the new keyword 75 | ``` 76 | 77 | (5). 78 | ``` 79 | const promise = new Promise((resolve, reject) => { 80 | console.log(1); 81 | setTimeout(() => { 82 | console.log("timerStart"); 83 | resolve("success"); 84 | console.log("timerEnd"); 85 | }, 0); 86 | console.log(2); 87 | }); 88 | promise.then((res) => { 89 | console.log(res); 90 | }); 91 | console.log(4); 92 | ``` 93 | 94 | (6). 95 | ``` 96 | const object = { 97 | who: 'World', 98 | 99 | greet() { 100 | return `Hello, ${this.who}!`; 101 | }, 102 | 103 | farewell: () => { 104 | return `Goodbye, ${this.who}!`; 105 | }, 106 | }; 107 | 108 | console.log(object.greet()); 109 | console.log(object.farewell()); 110 | ``` 111 | 112 | (7). 113 | ``` 114 | let arr = [0, 0, 0, 0, 0]; 115 | for (var i = 0; i < arr.length - 1; i++) { 116 | setTimeout(() => { 117 | ++arr[i]; 118 | console.log(arr); 119 | }, 1000 * i); 120 | } 121 | ``` 122 | 123 | (Q8). 124 | 125 | ``` 126 | 127 | console.log('a') 128 | 129 | async function b() { 130 | setTimeout(() => { 131 | console.log('b') 132 | }, 0) 133 | } 134 | b() 135 | 136 | console.log('c') 137 | 138 | async function d () { 139 | return new Promise ((resolve, reject) => { 140 | console.log('d') 141 | resolve() 142 | }) 143 | } 144 | d() 145 | 146 | console.log('e') 147 | 148 | 149 | Output: 150 | a 151 | c 152 | d 153 | e 154 | b 155 | 156 | ``` 157 | 158 | (Q9). 159 | 160 | ``` 161 | 162 | let a=b=4; 163 | console.log(a, b) 164 | 165 | 166 | Output : 167 | 4 4 168 | 169 | ``` 170 | 171 | (Q10). 172 | 173 | ``` 174 | 175 | function func () { 176 | console.log('1') 177 | setTimeout(() => { 178 | console.log('2') 179 | }, 0) 180 | console.log('3') 181 | } 182 | func() 183 | 184 | 185 | Output: 186 | 1 187 | 3 188 | 2 189 | 190 | ``` 191 | -------------------------------------------------------------------------------- /Important Questions/README.md: -------------------------------------------------------------------------------- 1 | ## Different ways to write [Filter]: 2 | 3 | const arr = [1,2,3,4,5,6]; 4 | ``` 5 | // Eg-1 6 | function logic (arr) { 7 | return arr > 2 8 | } 9 | const res = arr.filter(logic) 10 | ``` 11 | ``` 12 | // Eg-2 13 | const res2 = arr.filter(function logic (arr) { 14 | return arr > 2 15 | }) 16 | ``` 17 | ``` 18 | // Eg-3 19 | const res3 = arr.filter((arr) => { 20 | return arr > 2 21 | }) 22 | ``` 23 | ``` 24 | // Eg-4 25 | const res4 = arr.filter((arr) => arr > 2) 26 | ``` 27 | ``` 28 | // Eg-5 29 | function func (arr) { 30 | return arr>2; 31 | } 32 | Array.prototype.myFilter = function (logic) { 33 | const arr = []; 34 | for(let i=0;i { 80 | return arr.toString(2) 81 | }) 82 | ``` 83 | 84 | ``` 85 | // Eg-4 86 | const res4 = arr.map((arr) => arr.toString(2)) 87 | ``` 88 | 89 | ``` 90 | // Eg-5 91 | function func(arr) { 92 | return arr.toString(2) 93 | } 94 | Array.prototype.myMap = function (logic) { 95 | const res = []; 96 | for(let i=0;i { 144 | acc+=curr; 145 | return acc; 146 | }, 0) 147 | ``` 148 | 149 | ``` 150 | // Eg-4 151 | function logic2(acc, curr) { 152 | return acc+=curr; 153 | } 154 | const res4 = arr.reduce(logic2) 155 | ``` 156 | 157 | ``` 158 | // Eg-5 159 | function logic3(acc, curr) { 160 | return acc+=curr; 161 | } 162 | Array.prototype.myReduce = function (logic, initial) { 163 | let res = initial; 164 | for(let i=0;i