diff --git a/README.md b/README.md
index 0d6b4faa..b826be9d 100644
--- a/README.md
+++ b/README.md
@@ -46,818 +46,842 @@
### Table of Contents
-| No. | Questions |
-| --- | --------- |
-| 1 | [What are the possible ways to create objects in JavaScript](#what-are-the-possible-ways-to-create-objects-in-javascript) |
-| 2 | [What is a prototype chain](#what-is-a-prototype-chain) |
-| 3 | [What is the difference between Call, Apply and Bind](#what-is-the-difference-between-call-apply-and-bind) |
-| 4 | [What is JSON and its common operations](#what-is-json-and-its-common-operations) |
-| 5 | [What is the purpose of the array slice method](#what-is-the-purpose-of-the-array-slice-method) |
-| 6 | [What is the purpose of the array splice method](#what-is-the-purpose-of-the-array-splice-method) |
-| 7 | [What is the difference between slice and splice](#what-is-the-difference-between-slice-and-splice) |
-| 8 | [How do you compare Object and Map](#how-do-you-compare-object-and-map) |
-| 9 | [What is the difference between == and === operators](#what-is-the-difference-between--and--operators) |
-| 10 | [What are lambda expressions or arrow functions](#what-are-lambda-expressions-or-arrow-functions) |
-| 11 | [What is a first class function](#what-is-a-first-class-function) |
-| 12 | [What is a first order function](#what-is-a-first-order-function) |
-| 13 | [What is a higher order function](#what-is-a-higher-order-function) |
-| 14 | [What is a unary function](#what-is-a-unary-function) |
-| 15 | [What is the currying function](#what-is-the-currying-function) |
-| 16 | [What is a pure function](#what-is-a-pure-function) |
-| 17 | [What is the purpose of the let keyword](#what-is-the-purpose-of-the-let-keyword) |
-| 18 | [What is the difference between let and var](#what-is-the-difference-between-let-and-var) |
-| 19 | [What is the reason to choose the name let as a keyword](#what-is-the-reason-to-choose-the-name-let-as-a-keyword) |
-| 20 | [How do you redeclare variables in a switch block without an error](#how-do-you-redeclare-variables-in-a-switch-block-without-an-error) |
-| 21 | [What is the Temporal Dead Zone](#what-is-the-temporal-dead-zone) |
-| 22 | [What is an IIFE (Immediately Invoked Function Expression)](#what-is-an-iife-immediately-invoked-function-expression) |
-| 23 | [How do you decode or encode a URL in JavaScript?](#how-do-you-decode-or-encode-a-url-in-javascript) |
-| 24 | [What is memoization](#what-is-memoization) |
-| 25 | [What is Hoisting](#what-is-hoisting) |
-| 26 | [What are classes in ES6](#what-are-classes-in-es6) |
-| 27 | [What are closures](#what-are-closures) |
-| 28 | [What are modules](#what-are-modules) |
-| 29 | [Why do you need modules](#why-do-you-need-modules) |
-| 30 | [What is scope in javascript](#what-is-scope-in-javascript) |
-| 31 | [What is a service worker](#what-is-a-service-worker) |
-| 32 | [How do you manipulate DOM using a service worker](#how-do-you-manipulate-dom-using-a-service-worker) |
-| 33 | [How do you reuse information across service worker restarts](#how-do-you-reuse-information-across-service-worker-restarts) |
-| 34 | [What is IndexedDB](#what-is-indexeddb) |
-| 35 | [What is web storage](#what-is-web-storage) |
-| 36 | [What is a post message](#what-is-a-post-message) |
-| 37 | [What is a Cookie](#what-is-a-cookie) |
-| 38 | [Why do you need a Cookie](#why-do-you-need-a-cookie) |
-| 39 | [What are the options in a cookie](#what-are-the-options-in-a-cookie) |
-| 40 | [How do you delete a cookie](#how-do-you-delete-a-cookie) |
-| 41 | [What are the differences between cookie, local storage and session storage](#what-are-the-differences-between-cookie-local-storage-and-session-storage) |
-| 42 | [What is the main difference between localStorage and sessionStorage](#what-is-the-main-difference-between-localstorage-and-sessionstorage) |
-| 43 | [How do you access web storage](#how-do-you-access-web-storage) |
-| 44 | [What are the methods available on session storage](#what-are-the-methods-available-on-session-storage) |
-| 45 | [What is a storage event and its event handler](#what-is-a-storage-event-and-its-event-handler) |
-| 46 | [Why do you need web storage](#why-do-you-need-web-storage) |
-| 47 | [How do you check web storage browser support](#how-do-you-check-web-storage-browser-support) |
-| 48 | [How do you check web workers browser support](#how-do-you-check-web-workers-browser-support) |
-| 49 | [Give an example of a web worker](#give-an-example-of-a-web-worker) |
-| 50 | [What are the restrictions of web workers on DOM](#what-are-the-restrictions-of-web-workers-on-dom) |
-| 51 | [What is a promise](#what-is-a-promise) |
-| 52 | [Why do you need a promise](#why-do-you-need-a-promise) |
-| 53 | [What are the three states of promise](#what-are-the-three-states-of-promise) |
-| 54 | [What is a callback function](#what-is-a-callback-function) |
-| 55 | [Why do we need callbacks](#why-do-we-need-callbacks) |
-| 56 | [What is a callback hell](#what-is-a-callback-hell) |
-| 57 | [What are server-sent events](#what-are-server-sent-events) |
-| 58 | [How do you receive server-sent event notifications](#how-do-you-receive-server-sent-event-notifications) |
-| 59 | [How do you check browser support for server-sent events](#how-do-you-check-browser-support-for-server-sent-events) |
-| 60 | [What are the events available for server sent events](#what-are-the-events-available-for-server-sent-events) |
-| 61 | [What are the main rules of promise](#what-are-the-main-rules-of-promise) |
-| 62 | [What is callback in callback](#what-is-callback-in-callback) |
-| 63 | [What is promise chaining](#what-is-promise-chaining) |
-| 64 | [What is promise.all](#what-is-promiseall) |
-| 65 | [What is the purpose of the race method in promise](#what-is-the-purpose-of-the-race-method-in-promise) |
-| 66 | [What is a strict mode in javascript](#what-is-a-strict-mode-in-javascript) |
-| 67 | [Why do you need strict mode](#why-do-you-need-strict-mode) |
-| 68 | [How do you declare strict mode](#how-do-you-declare-strict-mode) |
-| 69 | [What is the purpose of double exclamation](#what-is-the-purpose-of-double-exclamation) |
-| 70 | [What is the purpose of the delete operator](#what-is-the-purpose-of-the-delete-operator) |
-| 71 | [What is typeof operator](#what-is-typeof-operator) |
-| 72 | [What is undefined property](#what-is-undefined-property) |
-| 73 | [What is null value](#what-is-null-value) |
-| 74 | [What is the difference between null and undefined](#what-is-the-difference-between-null-and-undefined) |
-| 75 | [What is eval](#what-is-eval) |
-| 76 | [What is the difference between window and document](#what-is-the-difference-between-window-and-document) |
-| 77 | [How do you access history in javascript](#how-do-you-access-history-in-javascript) |
-| 78 | [How do you detect caps lock key turned on or not](#how-do-you-detect-caps-lock-key-turned-on-or-not) |
-| 79 | [What is isNaN](#what-is-isnan) |
-| 80 | [What are the differences between undeclared and undefined variables](#what-are-the-differences-between-undeclared-and-undefined-variables) |
-| 81 | [What are global variables](#what-are-global-variables) |
-| 82 | [What are the problems with global variables](#what-are-the-problems-with-global-variables) |
-| 83 | [What is NaN property](#what-is-nan-property) |
-| 84 | [What is the purpose of isFinite function](#what-is-the-purpose-of-isfinite-function) |
-| 85 | [What is an event flow](#what-is-an-event-flow) |
-| 86 | [What is event bubbling](#what-is-event-bubbling) |
-| 87 | [What is event capturing](#what-is-event-capturing) |
-| 88 | [How do you submit a form using JavaScript](#how-do-you-submit-a-form-using-javascript) |
-| 89 | [How do you find operating system details](#how-do-you-find-operating-system-details) |
-| 90 | [What is the difference between document load and DOMContentLoaded events](#what-is-the-difference-between-document-load-and-domcontentloaded-events) |
-| 91 | [What is the difference between native, host and user objects](#what-is-the-difference-between-native-host-and-user-objects) |
-| 92 | [What are the tools or techniques used for debugging JavaScript code](#what-are-the-tools-or-techniques-used-for-debugging-javascript-code) |
-| 93 | [What are the pros and cons of promises over callbacks](#what-are-the-pros-and-cons-of-promises-over-callbacks) |
-| 94 | [What is the difference between an attribute and a property](#what-is-the-difference-between-an-attribute-and-a-property) |
-| 95 | [What is same-origin policy](#what-is-same-origin-policy) |
-| 96 | [What is the purpose of void 0](#what-is-the-purpose-of-void-0) |
-| 97 | [Is JavaScript a compiled or interpreted language](#is-javascript-a-compiled-or-interpreted-language) |
-| 98 | [Is JavaScript a case-sensitive language](#is-javascript-a-case-sensitive-language) |
-| 99 | [Is there any relation between Java and JavaScript](#is-there-any-relation-between-java-and-javascript) |
-| 100 | [What are events](#what-are-events) |
-| 101 | [Who created javascript](#who-created-javascript) |
-| 102 | [What is the use of preventDefault method](#what-is-the-use-of-preventdefault-method) |
-| 103 | [What is the use of stopPropagation method](#what-is-the-use-of-stoppropagation-method) |
-| 104 | [What are the steps involved in return false usage](#what-are-the-steps-involved-in-return-false-usage) |
-| 105 | [What is BOM](#what-is-bom) |
-| 106 | [What is the use of setTimeout](#what-is-the-use-of-settimeout) |
-| 107 | [What is the use of setInterval](#what-is-the-use-of-setinterval) |
-| 108 | [Why is JavaScript treated as Single threaded](#why-is-javascript-treated-as-single-threaded) |
-| 109 | [What is an event delegation](#what-is-an-event-delegation) |
-| 110 | [What is ECMAScript](#what-is-ecmascript) |
-| 111 | [What is JSON](#what-is-json) |
-| 112 | [What are the syntax rules of JSON](#what-are-the-syntax-rules-of-json) |
-| 113 | [What is the purpose JSON stringify](#what-is-the-purpose-json-stringify) |
-| 114 | [How do you parse JSON string](#how-do-you-parse-json-string) |
-| 115 | [Why do you need JSON](#why-do-you-need-json) |
-| 116 | [What are PWAs](#what-are-pwas) |
-| 117 | [What is the purpose of clearTimeout method](#what-is-the-purpose-of-cleartimeout-method) |
-| 118 | [What is the purpose of clearInterval method](#what-is-the-purpose-of-clearinterval-method) |
-| 119 | [How do you redirect new page in javascript](#how-do-you-redirect-new-page-in-javascript) |
-| 120 | [How do you check whether a string contains a substring](#how-do-you-check-whether-a-string-contains-a-substring) |
-| 121 | [How do you validate an email in javascript](#how-do-you-validate-an-email-in-javascript) |
-| 122 | [How do you get the current url with javascript](#how-do-you-get-the-current-url-with-javascript) |
-| 123 | [What are the various url properties of location object](#what-are-the-various-url-properties-of-location-object) |
-| 124 | [How do get query string values in javascript](#how-do-get-query-string-values-in-javascript) |
-| 125 | [How do you check if a key exists in an object](#how-do-you-check-if-a-key-exists-in-an-object) |
-| 126 | [How do you loop through or enumerate javascript object](#how-do-you-loop-through-or-enumerate-javascript-object) |
-| 127 | [How do you test for an empty object](#how-do-you-test-for-an-empty-object) |
-| 128 | [What is an arguments object](#what-is-an-arguments-object) |
-| 129 | [How do you make first letter of the string in an uppercase](#how-do-you-make-first-letter-of-the-string-in-an-uppercase) |
-| 130 | [What are the pros and cons of for loops](#what-are-the-pros-and-cons-of-for-loops) |
-| 131 | [How do you display the current date in javascript](#how-do-you-display-the-current-date-in-javascript) |
-| 132 | [How do you compare two date objects](#how-do-you-compare-two-date-objects) |
-| 133 | [How do you check if a string starts with another string](#how-do-you-check-if-a-string-starts-with-another-string) |
-| 134 | [How do you trim a string in javascript](#how-do-you-trim-a-string-in-javascript) |
-| 135 | [How do you add a key value pair in javascript](#how-do-you-add-a-key-value-pair-in-javascript) |
-| 136 | [Is the !-- notation represents a special operator](#is-the----notation-represents-a-special-operator) |
-| 137 | [How do you assign default values to variables](#how-do-you-assign-default-values-to-variables) |
-| 138 | [How do you define multiline strings](#how-do-you-define-multiline-strings) |
-| 139 | [What is an app shell model](#what-is-an-app-shell-model) |
-| 140 | [Can we define properties for functions](#can-we-define-properties-for-functions) |
-| 141 | [What is the way to find the number of parameters expected by a function](#what-is-the-way-to-find-the-number-of-parameters-expected-by-a-function) |
-| 142 | [What is a polyfill](#what-is-a-polyfill) |
-| 143 | [What are break and continue statements](#what-are-break-and-continue-statements) |
-| 144 | [What are js labels](#what-are-js-labels) |
-| 145 | [What are the benefits of keeping declarations at the top](#what-are-the-benefits-of-keeping-declarations-at-the-top) |
-| 146 | [What are the benefits of initializing variables](#what-are-the-benefits-of-initializing-variables) |
-| 147 | [What are the recommendations to create new object](#what-are-the-recommendations-to-create-new-object) |
-| 148 | [How do you define JSON arrays](#how-do-you-define-json-arrays) |
-| 149 | [How do you generate random integers](#how-do-you-generate-random-integers) |
-| 150 | [Can you write a random integers function to print integers within a range](#can-you-write-a-random-integers-function-to-print-integers-within-a-range) |
-| 151 | [What is tree shaking](#what-is-tree-shaking) |
-| 152 | [What is the need of tree shaking](#what-is-the-need-of-tree-shaking) |
-| 153 | [Is it recommended to use eval](#is-it-recommended-to-use-eval) |
-| 154 | [What is a Regular Expression](#what-is-a-regular-expression) |
-| 155 | [What are the string methods that accept Regular expression](#what-are-the-string-methods-that-accept-regular-expression) |
-| 156 | [What are modifiers in regular expression](#what-are-modifiers-in-regular-expression) |
-| 157 | [What are regular expression patterns](#what-are-regular-expression-patterns) |
-| 158 | [What is a RegExp object](#what-is-a-regexp-object) |
-| 159 | [How do you search a string for a pattern](#how-do-you-search-a-string-for-a-pattern) |
-| 160 | [What is the purpose of exec method](#what-is-the-purpose-of-exec-method) |
-| 161 | [How do you change the style of a HTML element](#how-do-you-change-the-style-of-a-html-element) |
-| 162 | [What would be the result of 1+2+'3'](#what-would-be-the-result-of-123) |
-| 163 | [What is a debugger statement](#what-is-a-debugger-statement) |
-| 164 | [What is the purpose of breakpoints in debugging](#what-is-the-purpose-of-breakpoints-in-debugging) |
-| 165 | [Can I use reserved words as identifiers](#can-i-use-reserved-words-as-identifiers) |
-| 166 | [How do you detect a mobile browser](#how-do-you-detect-a-mobile-browser) |
-| 167 | [How do you detect a mobile browser without regexp](#how-do-you-detect-a-mobile-browser-without-regexp) |
-| 168 | [How do you get the image width and height using JS](#how-do-you-get-the-image-width-and-height-using-js) |
-| 169 | [How do you make synchronous HTTP request](#how-do-you-make-synchronous-http-request) |
-| 170 | [How do you make asynchronous HTTP request](#how-do-you-make-asynchronous-http-request) |
-| 171 | [How do you convert date to another timezone in javascript](#how-do-you-convert-date-to-another-timezone-in-javascript) |
-| 172 | [What are the properties used to get size of window](#what-are-the-properties-used-to-get-size-of-window) |
-| 173 | [What is a conditional operator in javascript](#what-is-a-conditional-operator-in-javascript) |
-| 174 | [Can you apply chaining on conditional operator](#can-you-apply-chaining-on-conditional-operator) |
-| 175 | [What are the ways to execute javascript after page load](#what-are-the-ways-to-execute-javascript-after-page-load) |
-| 176 | [What is the difference between proto and prototype](#what-is-the-difference-between-proto-and-prototype) |
-| 177 | [Can you give an example of when you really need a semicolon](#can-you-give-an-example-of-when-you-really-need-a-semicolon) |
-| 178 | [What is a freeze method](#what-is-a-freeze-method) |
-| 179 | [What is the purpose of freeze method](#what-is-the-purpose-of-freeze-method) |
-| 180 | [Why do I need to use freeze method](#why-do-i-need-to-use-freeze-method) |
-| 181 | [How do you detect a browser language preference](#how-do-you-detect-a-browser-language-preference) |
-| 182 | [How to convert string to title case with javascript](#how-to-convert-string-to-title-case-with-javascript) |
-| 183 | [How do you detect javascript disabled in the page](#how-do-you-detect-javascript-disabled-in-the-page) |
-| 184 | [What are various operators supported by javascript](#what-are-various-operators-supported-by-javascript) |
-| 185 | [What is a rest parameter](#what-is-a-rest-parameter) |
-| 186 | [What happens if you do not use rest parameter as a last argument](#what-happens-if-you-do-not-use-rest-parameter-as-a-last-argument) |
-| 187 | [What are the bitwise operators available in javascript](#what-are-the-bitwise-operators-available-in-javascript) |
-| 188 | [What is a spread operator](#what-is-a-spread-operator) |
-| 189 | [How do you determine whether object is frozen or not](#how-do-you-determine-whether-object-is-frozen-or-not) |
-| 190 | [How do you determine two values same or not using object](#how-do-you-determine-two-values-same-or-not-using-object) |
-| 191 | [What is the purpose of using object is method](#what-is-the-purpose-of-using-object-is-method) |
-| 192 | [How do you copy properties from one object to other](#how-do-you-copy-properties-from-one-object-to-other) |
-| 193 | [What are the applications of assign method](#what-are-the-applications-of-assign-method) |
-| 194 | [What is a proxy object](#what-is-a-proxy-object) |
-| 195 | [What is the purpose of seal method](#what-is-the-purpose-of-seal-method) |
-| 196 | [What are the applications of seal method](#what-are-the-applications-of-seal-method) |
-| 197 | [What are the differences between freeze and seal methods](#what-are-the-differences-between-freeze-and-seal-methods) |
-| 198 | [How do you determine if an object is sealed or not](#how-do-you-determine-if-an-object-is-sealed-or-not) |
-| 199 | [How do you get enumerable key and value pairs](#how-do-you-get-enumerable-key-and-value-pairs) |
-| 200 | [What is the main difference between Object.values and Object.entries method](#what-is-the-main-difference-between-objectvalues-and-objectentries-method) |
-| 201 | [How can you get the list of keys of any object](#how-can-you-get-the-list-of-keys-of-any-object) |
-| 202 | [How do you create an object with prototype](#how-do-you-create-an-object-with-prototype) |
-| 203 | [What is a WeakSet](#what-is-a-weakset) |
-| 204 | [What are the differences between WeakSet and Set](#what-are-the-differences-between-weakset-and-set) |
-| 205 | [List down the collection of methods available on WeakSet](#list-down-the-collection-of-methods-available-on-weakset) |
-| 206 | [What is a WeakMap](#what-is-a-weakmap) |
-| 207 | [What are the differences between WeakMap and Map](#what-are-the-differences-between-weakmap-and-map) |
-| 208 | [List down the collection of methods available on WeakMap](#list-down-the-collection-of-methods-available-on-weakmap) |
-| 209 | [What is the purpose of uneval](#what-is-the-purpose-of-uneval) |
-| 210 | [How do you encode an URL](#how-do-you-encode-an-url) |
-| 211 | [How do you decode an URL](#how-do-you-decode-an-url) |
-| 212 | [How do you print the contents of web page](#how-do-you-print-the-contents-of-web-page) |
-| 213 | [What is the difference between uneval and eval](#what-is-the-difference-between-uneval-and-eval) |
-| 214 | [What is an anonymous function](#what-is-an-anonymous-function) |
-| 215 | [What is the precedence order between local and global variables](#what-is-the-precedence-order-between-local-and-global-variables) |
-| 216 | [What are javascript accessors](#what-are-javascript-accessors) |
-| 217 | [How do you define property on Object constructor](#how-do-you-define-property-on-object-constructor) |
-| 218 | [What is the difference between get and defineProperty](#what-is-the-difference-between-get-and-defineproperty) |
-| 219 | [What are the advantages of Getters and Setters](#what-are-the-advantages-of-getters-and-setters) |
-| 220 | [Can I add getters and setters using defineProperty method](#can-i-add-getters-and-setters-using-defineproperty-method) |
-| 221 | [What is the purpose of switch-case](#what-is-the-purpose-of-switch-case) |
-| 222 | [What are the conventions to be followed for the usage of switch case](#what-are-the-conventions-to-be-followed-for-the-usage-of-switch-case) |
-| 223 | [What are primitive data types](#what-are-primitive-data-types) |
-| 224 | [What are the different ways to access object properties](#what-are-the-different-ways-to-access-object-properties) |
-| 225 | [What are the function parameter rules](#what-are-the-function-parameter-rules) |
-| 226 | [What is an error object](#what-is-an-error-object) |
-| 227 | [When you get a syntax error](#when-you-get-a-syntax-error) |
-| 228 | [What are the different error names from error object](#what-are-the-different-error-names-from-error-object) |
-| 229 | [What are the various statements in error handling](#what-are-the-various-statements-in-error-handling) |
-| 230 | [What are the two types of loops in javascript](#what-are-the-two-types-of-loops-in-javascript) |
-| 231 | [What is nodejs](#what-is-nodejs) |
-| 232 | [What is an Intl object](#what-is-an-intl-object) |
-| 233 | [How do you perform language specific date and time formatting](#how-do-you-perform-language-specific-date-and-time-formatting) |
-| 234 | [What is an Iterator](#what-is-an-iterator) |
-| 235 | [How does synchronous iteration works](#how-does-synchronous-iteration-works) |
-| 236 | [What is an event loop](#what-is-an-event-loop) |
-| 237 | [What is call stack](#what-is-call-stack) |
-| 238 | [What is an event queue](#what-is-an-event-queue) |
-| 239 | [What is a decorator](#what-is-a-decorator) |
-| 240 | [What are the properties of Intl object](#what-are-the-properties-of-intl-object) |
-| 241 | [What is an Unary operator](#what-is-an-unary-operator) |
-| 242 | [How do you sort elements in an array](#how-do-you-sort-elements-in-an-array) |
-| 243 | [What is the purpose of compareFunction while sorting arrays](#what-is-the-purpose-of-comparefunction-while-sorting-arrays) |
-| 244 | [How do you reversing an array](#how-do-you-reversing-an-array) |
-| 245 | [How do you find min and max value in an array](#how-do-you-find-min-and-max-value-in-an-array) |
-| 246 | [How do you find min and max values without Math functions](#how-do-you-find-min-and-max-values-without-math-functions) |
-| 247 | [What is an empty statement and purpose of it](#what-is-an-empty-statement-and-purpose-of-it) |
-| 248 | [How do you get metadata of a module](#how-do-you-get-metadata-of-a-module) |
-| 249 | [What is a comma operator](#what-is-a-comma-operator) |
-| 250 | [What is the advantage of a comma operator](#what-is-the-advantage-of-a-comma-operator) |
-| 251 | [What is typescript](#what-is-typescript) |
-| 252 | [What are the differences between javascript and typescript](#what-are-the-differences-between-javascript-and-typescript) |
-| 253 | [What are the advantages of typescript over javascript](#what-are-the-advantages-of-typescript-over-javascript) |
-| 254 | [What is an object initializer](#what-is-an-object-initializer) |
-| 255 | [What is a constructor method](#what-is-a-constructor-method) |
-| 256 | [What happens if you write constructor more than once in a class](#what-happens-if-you-write-constructor-more-than-once-in-a-class) |
-| 257 | [How do you call the constructor of a parent class](#how-do-you-call-the-constructor-of-a-parent-class) |
-| 258 | [How do you get the prototype of an object](#how-do-you-get-the-prototype-of-an-object) |
-| 259 | [What happens If I pass string type for getPrototype method](#what-happens-if-i-pass-string-type-for-getprototype-method) |
-| 260 | [How do you set prototype of one object to another](#how-do-you-set-prototype-of-one-object-to-another) |
-| 261 | [How do you check whether an object can be extendable or not](#how-do-you-check-whether-an-object-can-be-extendable-or-not) |
-| 262 | [How do you prevent an object to extend](#how-do-you-prevent-an-object-to-extend) |
-| 263 | [What are the different ways to make an object non-extensible](#what-are-the-different-ways-to-make-an-object-non-extensible) |
-| 264 | [How do you define multiple properties on an object](#how-do-you-define-multiple-properties-on-an-object) |
-| 265 | [What is MEAN in javascript](#what-is-mean-in-javascript) |
-| 266 | [What Is Obfuscation in javascript](#what-is-obfuscation-in-javascript) |
-| 267 | [Why do you need Obfuscation](#why-do-you-need-obfuscation) |
-| 268 | [What is Minification](#what-is-minification) |
-| 269 | [What are the advantages of minification](#what-are-the-advantages-of-minification) |
-| 270 | [What are the differences between Obfuscation and Encryption](#what-are-the-differences-between-obfuscation-and-encryption) |
-| 271 | [What are the common tools used for minification](#what-are-the-common-tools-used-for-minification) |
-| 272 | [How do you perform form validation using javascript](#how-do-you-perform-form-validation-using-javascript) |
-| 273 | [How do you perform form validation without javascript](#how-do-you-perform-form-validation-without-javascript) |
-| 274 | [What are the DOM methods available for constraint validation](#what-are-the-dom-methods-available-for-constraint-validation) |
-| 275 | [What are the available constraint validation DOM properties](#what-are-the-available-constraint-validation-dom-properties) |
-| 276 | [What are the list of validity properties](#what-are-the-list-of-validity-properties) |
-| 277 | [Give an example usage of rangeOverflow property](#give-an-example-usage-of-rangeoverflow-property) |
-| 278 | [Is enums feature available in javascript](#is-enums-feature-available-in-javascript) |
-| 279 | [What is an enum](#what-is-an-enum) |
-| 280 | [How do you list all properties of an object](#how-do-you-list-all-properties-of-an-object) |
-| 281 | [How do you get property descriptors of an object](#how-do-you-get-property-descriptors-of-an-object) |
-| 282 | [What are the attributes provided by a property descriptor](#what-are-the-attributes-provided-by-a-property-descriptor) |
-| 283 | [How do you extend classes](#how-do-you-extend-classes) |
-| 284 | [How do I modify the url without reloading the page](#how-do-i-modify-the-url-without-reloading-the-page) |
-| 285 | [How do you check whether an array includes a particular value or not](#how-do-you-check-whether-an-array-includes-a-particular-value-or-not) |
-| 286 | [How do you compare scalar arrays](#how-do-you-compare-scalar-arrays) |
-| 287 | [How to get the value from get parameters](#how-to-get-the-value-from-get-parameters) |
-| 288 | [How do you print numbers with commas as thousand separators](#how-do-you-print-numbers-with-commas-as-thousand-separators) |
-| 289 | [What is the difference between java and javascript](#what-is-the-difference-between-java-and-javascript) |
-| 290 | [Does JavaScript supports namespace](#does-javascript-supports-namespace) |
-| 291 | [How do you declare namespace](#how-do-you-declare-namespace) |
-| 292 | [How do you invoke javascript code in an iframe from parent page](#how-do-you-invoke-javascript-code-in-an-iframe-from-parent-page) |
-| 293 | [How do get the timezone offset from date](#how-do-get-the-timezone-offset-from-date) |
-| 294 | [How do you load CSS and JS files dynamically](#how-do-you-load-css-and-js-files-dynamically) |
-| 295 | [What are the different methods to find HTML elements in DOM](#what-are-the-different-methods-to-find-html-elements-in-dom) |
-| 296 | [What is jQuery](#what-is-jquery) |
-| 297 | [What is V8 JavaScript engine](#what-is-v8-javascript-engine) |
-| 298 | [Why do we call javascript as dynamic language](#why-do-we-call-javascript-as-dynamic-language) |
-| 299 | [What is a void operator](#what-is-a-void-operator) |
-| 300 | [How to set the cursor to wait](#how-to-set-the-cursor-to-wait) |
-| 301 | [How do you create an infinite loop](#how-do-you-create-an-infinite-loop) |
-| 302 | [Why do you need to avoid with statement](#why-do-you-need-to-avoid-with-statement) |
-| 303 | [What is the output of the following for loops](#what-is-the-output-of-the-following-for-loops) |
-| 304 | [List down some of the features of ES6](#list-down-some-of-the-features-of-es6) |
-| 305 | [What is ES6](#what-is-es6) |
-| 306 | [Can I redeclare let and const variables](#can-i-redeclare-let-and-const-variables) |
-| 307 | [Does the `const` variable make the value immutable](#does-the-const-variable-make-the-value-immutable) |
-| 308 | [What are default parameters](#what-are-default-parameters) |
-| 309 | [What are template literals](#what-are-template-literals) |
-| 310 | [How do you write multi-line strings in template literals](#how-do-you-write-multi-line-strings-in-template-literals) |
-| 311 | [What are nesting templates](#what-are-nesting-templates) |
-| 312 | [What are tagged templates](#what-are-tagged-templates) |
-| 313 | [What are raw strings](#what-are-raw-strings) |
-| 314 | [What is destructuring assignment](#what-is-destructuring-assignment) |
-| 315 | [What are default values in destructuring assignment](#what-are-default-values-in-destructuring-assignment) |
-| 316 | [How do you swap variables in destructuring assignment](#how-do-you-swap-variables-in-destructuring-assignment) |
-| 317 | [What are enhanced object literals](#what-are-enhanced-object-literals) |
-| 318 | [What are dynamic imports](#what-are-dynamic-imports) |
-| 319 | [What are the use cases for dynamic imports](#what-are-the-use-cases-for-dynamic-imports) |
-| 320 | [What are typed arrays](#what-are-typed-arrays) |
-| 321 | [What are the advantages of module loaders](#what-are-the-advantages-of-module-loaders) |
-| 322 | [What is collation](#what-is-collation) |
-| 323 | [What is for...of statement](#what-is-forof-statement) |
-| 324 | [What is the output of below spread operator array](#what-is-the-output-of-below-spread-operator-array) |
-| 325 | [Is PostMessage secure](#is-postmessage-secure) |
-| 326 | [What are the problems with postmessage target origin as wildcard](#what-are-the-problems-with-postmessage-target-origin-as-wildcard) |
-| 327 | [How do you avoid receiving postMessages from attackers](#how-do-you-avoid-receiving-postmessages-from-attackers) |
-| 328 | [Can I avoid using postMessages completely](#can-i-avoid-using-postmessages-completely) |
-| 329 | [Is postMessages synchronous](#is-postmessages-synchronous) |
-| 330 | [What paradigm is Javascript](#what-paradigm-is-javascript) |
-| 331 | [What is the difference between internal and external javascript](#what-is-the-difference-between-internal-and-external-javascript) |
-| 332 | [Is JavaScript faster than server side script](#is-javascript-faster-than-server-side-script) |
-| 333 | [How do you get the status of a checkbox](#how-do-you-get-the-status-of-a-checkbox) |
-| 334 | [What is the purpose of double tilde operator](#what-is-the-purpose-of-double-tilde-operator) |
-| 335 | [How do you convert character to ASCII code](#how-do-you-convert-character-to-ascii-code) |
-| 336 | [What is ArrayBuffer](#what-is-arraybuffer) |
-| 337 | [What is the output of below string expression](#what-is-the-output-of-below-string-expression) |
-| 338 | [What is the purpose of Error object](#what-is-the-purpose-of-error-object) |
-| 339 | [What is the purpose of EvalError object](#what-is-the-purpose-of-evalerror-object) |
-| 340 | [What are the list of cases error thrown from non-strict mode to strict mode](#what-are-the-list-of-cases-error-thrown-from-non-strict-mode-to-strict-mode) |
-| 341 | [Do all objects have prototypes](#do-all-objects-have-prototypes) |
-| 342 | [What is the difference between a parameter and an argument](#what-is-the-difference-between-a-parameter-and-an-argument) |
-| 343 | [What is the purpose of some method in arrays](#what-is-the-purpose-of-some-method-in-arrays) |
-| 344 | [How do you combine two or more arrays](#how-do-you-combine-two-or-more-arrays) |
-| 345 | [What is the difference between Shallow and Deep copy](#what-is-the-difference-between-shallow-and-deep-copy) |
-| 346 | [How do you create specific number of copies of a string](#how-do-you-create-specific-number-of-copies-of-a-string) |
-| 347 | [How do you return all matching strings against a regular expression](#how-do-you-return-all-matching-strings-against-a-regular-expression) |
-| 348 | [How do you trim a string at the beginning or ending](#how-do-you-trim-a-string-at-the-beginning-or-ending) |
-| 349 | [What is the output of below console statement with unary operator](#what-is-the-output-of-below-console-statement-with-unary-operator) |
-| 350 | [Does javascript uses mixins](#does-javascript-uses-mixins) |
-| 351 | [What is a thunk function](#what-is-a-thunk-function) |
-| 352 | [What are asynchronous thunks](#what-are-asynchronous-thunks) |
-| 353 | [What is the output of below function calls](#what-is-the-output-of-below-function-calls) |
-| 354 | [How to remove all line breaks from a string](#how-to-remove-all-line-breaks-from-a-string) |
-| 355 | [What is the difference between reflow and repaint](#what-is-the-difference-between-reflow-and-repaint) |
-| 356 | [What happens with negating an array](#what-happens-with-negating-an-array) |
-| 357 | [What happens if we add two arrays](#what-happens-if-we-add-two-arrays) |
-| 358 | [What is the output of prepend additive operator on falsy values](#what-is-the-output-of-prepend-additive-operator-on-falsy-values) |
-| 359 | [How do you create self string using special characters](#how-do-you-create-self-string-using-special-characters) |
-| 360 | [How do you remove falsy values from an array](#how-do-you-remove-falsy-values-from-an-array) |
-| 361 | [How do you get unique values of an array](#how-do-you-get-unique-values-of-an-array) |
-| 362 | [What is destructuring aliases](#what-is-destructuring-aliases) |
-| 363 | [How do you map the array values without using map method](#how-do-you-map-the-array-values-without-using-map-method) |
-| 364 | [How do you empty an array](#how-do-you-empty-an-array) |
-| 365 | [How do you round numbers to certain decimals](#how-do-you-round-numbers-to-certain-decimals) |
-| 366 | [What is the easiest way to convert an array to an object](#what-is-the-easiest-way-to-convert-an-array-to-an-object) |
-| 367 | [How do you create an array with some data](#how-do-you-create-an-array-with-some-data) |
-| 368 | [What are the placeholders from console object](#what-are-the-placeholders-from-console-object) |
-| 369 | [Is it possible to add CSS to console messages](#is-it-possible-to-add-css-to-console-messages) |
-| 370 | [What is the purpose of dir method of console object](#what-is-the-purpose-of-dir-method-of-console-object) |
-| 371 | [Is it possible to debug HTML elements in console](#is-it-possible-to-debug-html-elements-in-console) |
-| 372 | [How do you display data in a tabular format using console object](#how-do-you-display-data-in-a-tabular-format-using-console-object) |
-| 373 | [How do you verify that an argument is a Number or not](#how-do-you-verify-that-an-argument-is-a-number-or-not) |
-| 374 | [How do you create copy to clipboard button](#how-do-you-create-copy-to-clipboard-button) |
-| 375 | [What is the shortcut to get timestamp](#what-is-the-shortcut-to-get-timestamp) |
-| 376 | [How do you flattening multi dimensional arrays](#how-do-you-flattening-multi-dimensional-arrays) |
-| 377 | [What is the easiest multi condition checking](#what-is-the-easiest-multi-condition-checking) |
-| 378 | [How do you capture browser back button](#how-do-you-capture-browser-back-button) |
-| 379 | [How do you disable right click in the web page](#how-do-you-disable-right-click-in-the-web-page) |
-| 380 | [What are wrapper objects](#what-are-wrapper-objects) |
-| 381 | [What is AJAX](#what-is-ajax) |
-| 382 | [What are the different ways to deal with Asynchronous Code](#what-are-the-different-ways-to-deal-with-asynchronous-code) |
-| 383 | [How to cancel a fetch request](#how-to-cancel-a-fetch-request) |
-| 384 | [What is web speech API](#what-is-web-speech-api) |
-| 385 | [What is minimum timeout throttling](#what-is-minimum-timeout-throttling) |
-| 386 | [How do you implement zero timeout in modern browsers](#how-do-you-implement-zero-timeout-in-modern-browsers) |
-| 387 | [What are tasks in event loop](#what-are-tasks-in-event-loop) |
-| 388 | [What is microtask](#what-is-microtask) |
-| 389 | [What are different event loops](#what-are-different-event-loops) |
-| 390 | [What is the purpose of queueMicrotask](#what-is-the-purpose-of-queuemicrotask) |
-| 391 | [How do you use javascript libraries in typescript file](#how-do-you-use-javascript-libraries-in-typescript-file) |
-| 392 | [What are the differences between promises and observables](#what-are-the-differences-between-promises-and-observables) |
-| 393 | [What is heap](#what-is-heap) |
-| 394 | [What is an event table](#what-is-an-event-table) |
-| 395 | [What is a microTask queue](#what-is-a-microtask-queue) |
-| 396 | [What is the difference between shim and polyfill](#what-is-the-difference-between-shim-and-polyfill) |
-| 397 | [How do you detect primitive or non primitive value type](#how-do-you-detect-primitive-or-non-primitive-value-type) |
-| 398 | [What is babel](#what-is-babel) |
-| 399 | [Is Node.js completely single threaded](#is-nodejs-completely-single-threaded) |
-| 400 | [What are the common use cases of observables](#what-are-the-common-use-cases-of-observables) |
-| 401 | [What is RxJS](#what-is-rxjs) |
+
+| No. | Questions |
+| --- | ------------------------------------------------------------------------------------------------------------------------------------------------------------- |
+| 1 | [What are the possible ways to create objects in JavaScript](#what-are-the-possible-ways-to-create-objects-in-javascript) |
+| 2 | [What is a prototype chain](#what-is-a-prototype-chain) |
+| 3 | [What is the difference between Call, Apply and Bind](#what-is-the-difference-between-call-apply-and-bind) |
+| 4 | [What is JSON and its common operations](#what-is-json-and-its-common-operations) |
+| 5 | [What is the purpose of the array slice method](#what-is-the-purpose-of-the-array-slice-method) |
+| 6 | [What is the purpose of the array splice method](#what-is-the-purpose-of-the-array-splice-method) |
+| 7 | [What is the difference between slice and splice](#what-is-the-difference-between-slice-and-splice) |
+| 8 | [How do you compare Object and Map](#how-do-you-compare-object-and-map) |
+| 9 | [What is the difference between == and === operators](#what-is-the-difference-between--and--operators) |
+| 10 | [What are lambda expressions or arrow functions](#what-are-lambda-expressions-or-arrow-functions) |
+| 11 | [What is a first class function](#what-is-a-first-class-function) |
+| 12 | [What is a first order function](#what-is-a-first-order-function) |
+| 13 | [What is a higher order function](#what-is-a-higher-order-function) |
+| 14 | [What is a unary function](#what-is-a-unary-function) |
+| 15 | [What is the currying function](#what-is-the-currying-function) |
+| 16 | [What is a pure function](#what-is-a-pure-function) |
+| 17 | [What is the purpose of the let keyword](#what-is-the-purpose-of-the-let-keyword) |
+| 18 | [What is the difference between let and var](#what-is-the-difference-between-let-and-var) |
+| 19 | [What is the reason to choose the name let as a keyword](#what-is-the-reason-to-choose-the-name-let-as-a-keyword) |
+| 20 | [How do you redeclare variables in a switch block without an error](#how-do-you-redeclare-variables-in-a-switch-block-without-an-error) |
+| 21 | [What is the Temporal Dead Zone](#what-is-the-temporal-dead-zone) |
+| 22 | [What is an IIFE (Immediately Invoked Function Expression)](#what-is-an-iife-immediately-invoked-function-expression) |
+| 23 | [How do you decode or encode a URL in JavaScript?](#how-do-you-decode-or-encode-a-url-in-javascript) |
+| 24 | [What is memoization](#what-is-memoization) |
+| 25 | [What is Hoisting](#what-is-hoisting) |
+| 26 | [What are classes in ES6](#what-are-classes-in-es6) |
+| 27 | [What are closures](#what-are-closures) |
+| 28 | [What are modules](#what-are-modules) |
+| 29 | [Why do you need modules](#why-do-you-need-modules) |
+| 30 | [What is scope in javascript](#what-is-scope-in-javascript) |
+| 31 | [What is a service worker](#what-is-a-service-worker) |
+| 32 | [How do you manipulate DOM using a service worker](#how-do-you-manipulate-dom-using-a-service-worker) |
+| 33 | [How do you reuse information across service worker restarts](#how-do-you-reuse-information-across-service-worker-restarts) |
+| 34 | [What is IndexedDB](#what-is-indexeddb) |
+| 35 | [What is web storage](#what-is-web-storage) |
+| 36 | [What is a post message](#what-is-a-post-message) |
+| 37 | [What is a Cookie](#what-is-a-cookie) |
+| 38 | [Why do you need a Cookie](#why-do-you-need-a-cookie) |
+| 39 | [What are the options in a cookie](#what-are-the-options-in-a-cookie) |
+| 40 | [How do you delete a cookie](#how-do-you-delete-a-cookie) |
+| 41 | [What are the differences between cookie, local storage and session storage](#what-are-the-differences-between-cookie-local-storage-and-session-storage) |
+| 42 | [What is the main difference between localStorage and sessionStorage](#what-is-the-main-difference-between-localstorage-and-sessionstorage) |
+| 43 | [How do you access web storage](#how-do-you-access-web-storage) |
+| 44 | [What are the methods available on session storage](#what-are-the-methods-available-on-session-storage) |
+| 45 | [What is a storage event and its event handler](#what-is-a-storage-event-and-its-event-handler) |
+| 46 | [Why do you need web storage](#why-do-you-need-web-storage) |
+| 47 | [How do you check web storage browser support](#how-do-you-check-web-storage-browser-support) |
+| 48 | [How do you check web workers browser support](#how-do-you-check-web-workers-browser-support) |
+| 49 | [Give an example of a web worker](#give-an-example-of-a-web-worker) |
+| 50 | [What are the restrictions of web workers on DOM](#what-are-the-restrictions-of-web-workers-on-dom) |
+| 51 | [What is a promise](#what-is-a-promise) |
+| 52 | [Why do you need a promise](#why-do-you-need-a-promise) |
+| 53 | [What are the three states of promise](#what-are-the-three-states-of-promise) |
+| 54 | [What is a callback function](#what-is-a-callback-function) |
+| 55 | [Why do we need callbacks](#why-do-we-need-callbacks) |
+| 56 | [What is a callback hell](#what-is-a-callback-hell) |
+| 57 | [What are server-sent events](#what-are-server-sent-events) |
+| 58 | [How do you receive server-sent event notifications](#how-do-you-receive-server-sent-event-notifications) |
+| 59 | [How do you check browser support for server-sent events](#how-do-you-check-browser-support-for-server-sent-events) |
+| 60 | [What are the events available for server sent events](#what-are-the-events-available-for-server-sent-events) |
+| 61 | [What are the main rules of promise](#what-are-the-main-rules-of-promise) |
+| 62 | [What is callback in callback](#what-is-callback-in-callback) |
+| 63 | [What is promise chaining](#what-is-promise-chaining) |
+| 64 | [What is promise.all](#what-is-promiseall) |
+| 65 | [What is the purpose of the race method in promise](#what-is-the-purpose-of-the-race-method-in-promise) |
+| 66 | [What is a strict mode in javascript](#what-is-a-strict-mode-in-javascript) |
+| 67 | [Why do you need strict mode](#why-do-you-need-strict-mode) |
+| 68 | [How do you declare strict mode](#how-do-you-declare-strict-mode) |
+| 69 | [What is the purpose of double exclamation](#what-is-the-purpose-of-double-exclamation) |
+| 70 | [What is the purpose of the delete operator](#what-is-the-purpose-of-the-delete-operator) |
+| 71 | [What is typeof operator](#what-is-typeof-operator) |
+| 72 | [What is undefined property](#what-is-undefined-property) |
+| 73 | [What is null value](#what-is-null-value) |
+| 74 | [What is the difference between null and undefined](#what-is-the-difference-between-null-and-undefined) |
+| 75 | [What is eval](#what-is-eval) |
+| 76 | [What is the difference between window and document](#what-is-the-difference-between-window-and-document) |
+| 77 | [How do you access history in javascript](#how-do-you-access-history-in-javascript) |
+| 78 | [How do you detect caps lock key turned on or not](#how-do-you-detect-caps-lock-key-turned-on-or-not) |
+| 79 | [What is isNaN](#what-is-isnan) |
+| 80 | [What are the differences between undeclared and undefined variables](#what-are-the-differences-between-undeclared-and-undefined-variables) |
+| 81 | [What are global variables](#what-are-global-variables) |
+| 82 | [What are the problems with global variables](#what-are-the-problems-with-global-variables) |
+| 83 | [What is NaN property](#what-is-nan-property) |
+| 84 | [What is the purpose of isFinite function](#what-is-the-purpose-of-isfinite-function) |
+| 85 | [What is an event flow](#what-is-an-event-flow) |
+| 86 | [What is event bubbling](#what-is-event-bubbling) |
+| 87 | [What is event capturing](#what-is-event-capturing) |
+| 88 | [How do you submit a form using JavaScript](#how-do-you-submit-a-form-using-javascript) |
+| 89 | [How do you find operating system details](#how-do-you-find-operating-system-details) |
+| 90 | [What is the difference between document load and DOMContentLoaded events](#what-is-the-difference-between-document-load-and-domcontentloaded-events) |
+| 91 | [What is the difference between native, host and user objects](#what-is-the-difference-between-native-host-and-user-objects) |
+| 92 | [What are the tools or techniques used for debugging JavaScript code](#what-are-the-tools-or-techniques-used-for-debugging-javascript-code) |
+| 93 | [What are the pros and cons of promises over callbacks](#what-are-the-pros-and-cons-of-promises-over-callbacks) |
+| 94 | [What is the difference between an attribute and a property](#what-is-the-difference-between-an-attribute-and-a-property) |
+| 95 | [What is same-origin policy](#what-is-same-origin-policy) |
+| 96 | [What is the purpose of void 0](#what-is-the-purpose-of-void-0) |
+| 97 | [Is JavaScript a compiled or interpreted language](#is-javascript-a-compiled-or-interpreted-language) |
+| 98 | [Is JavaScript a case-sensitive language](#is-javascript-a-case-sensitive-language) |
+| 99 | [Is there any relation between Java and JavaScript](#is-there-any-relation-between-java-and-javascript) |
+| 100 | [What are events](#what-are-events) |
+| 101 | [Who created javascript](#who-created-javascript) |
+| 102 | [What is the use of preventDefault method](#what-is-the-use-of-preventdefault-method) |
+| 103 | [What is the use of stopPropagation method](#what-is-the-use-of-stoppropagation-method) |
+| 104 | [What are the steps involved in return false usage](#what-are-the-steps-involved-in-return-false-usage) |
+| 105 | [What is BOM](#what-is-bom) |
+| 106 | [What is the use of setTimeout](#what-is-the-use-of-settimeout) |
+| 107 | [What is the use of setInterval](#what-is-the-use-of-setinterval) |
+| 108 | [Why is JavaScript treated as Single threaded](#why-is-javascript-treated-as-single-threaded) |
+| 109 | [What is an event delegation](#what-is-an-event-delegation) |
+| 110 | [What is ECMAScript](#what-is-ecmascript) |
+| 111 | [What is JSON](#what-is-json) |
+| 112 | [What are the syntax rules of JSON](#what-are-the-syntax-rules-of-json) |
+| 113 | [What is the purpose JSON stringify](#what-is-the-purpose-json-stringify) |
+| 114 | [How do you parse JSON string](#how-do-you-parse-json-string) |
+| 115 | [Why do you need JSON](#why-do-you-need-json) |
+| 116 | [What are PWAs](#what-are-pwas) |
+| 117 | [What is the purpose of clearTimeout method](#what-is-the-purpose-of-cleartimeout-method) |
+| 118 | [What is the purpose of clearInterval method](#what-is-the-purpose-of-clearinterval-method) |
+| 119 | [How do you redirect new page in javascript](#how-do-you-redirect-new-page-in-javascript) |
+| 120 | [How do you check whether a string contains a substring](#how-do-you-check-whether-a-string-contains-a-substring) |
+| 121 | [How do you validate an email in javascript](#how-do-you-validate-an-email-in-javascript) |
+| 122 | [How do you get the current url with javascript](#how-do-you-get-the-current-url-with-javascript) |
+| 123 | [What are the various url properties of location object](#what-are-the-various-url-properties-of-location-object) |
+| 124 | [How do get query string values in javascript](#how-do-get-query-string-values-in-javascript) |
+| 125 | [How do you check if a key exists in an object](#how-do-you-check-if-a-key-exists-in-an-object) |
+| 126 | [How do you loop through or enumerate javascript object](#how-do-you-loop-through-or-enumerate-javascript-object) |
+| 127 | [How do you test for an empty object](#how-do-you-test-for-an-empty-object) |
+| 128 | [What is an arguments object](#what-is-an-arguments-object) |
+| 129 | [How do you make first letter of the string in an uppercase](#how-do-you-make-first-letter-of-the-string-in-an-uppercase) |
+| 130 | [What are the pros and cons of for loops](#what-are-the-pros-and-cons-of-for-loops) |
+| 131 | [How do you display the current date in javascript](#how-do-you-display-the-current-date-in-javascript) |
+| 132 | [How do you compare two date objects](#how-do-you-compare-two-date-objects) |
+| 133 | [How do you check if a string starts with another string](#how-do-you-check-if-a-string-starts-with-another-string) |
+| 134 | [How do you trim a string in javascript](#how-do-you-trim-a-string-in-javascript) |
+| 135 | [How do you add a key value pair in javascript](#how-do-you-add-a-key-value-pair-in-javascript) |
+| 136 | [Is the !-- notation represents a special operator](#is-the----notation-represents-a-special-operator) |
+| 137 | [How do you assign default values to variables](#how-do-you-assign-default-values-to-variables) |
+| 138 | [How do you define multiline strings](#how-do-you-define-multiline-strings) |
+| 139 | [What is an app shell model](#what-is-an-app-shell-model) |
+| 140 | [Can we define properties for functions](#can-we-define-properties-for-functions) |
+| 141 | [What is the way to find the number of parameters expected by a function](#what-is-the-way-to-find-the-number-of-parameters-expected-by-a-function) |
+| 142 | [What is a polyfill](#what-is-a-polyfill) |
+| 143 | [What are break and continue statements](#what-are-break-and-continue-statements) |
+| 144 | [What are js labels](#what-are-js-labels) |
+| 145 | [What are the benefits of keeping declarations at the top](#what-are-the-benefits-of-keeping-declarations-at-the-top) |
+| 146 | [What are the benefits of initializing variables](#what-are-the-benefits-of-initializing-variables) |
+| 147 | [What are the recommendations to create new object](#what-are-the-recommendations-to-create-new-object) |
+| 148 | [How do you define JSON arrays](#how-do-you-define-json-arrays) |
+| 149 | [How do you generate random integers](#how-do-you-generate-random-integers) |
+| 150 | [Can you write a random integers function to print integers within a range](#can-you-write-a-random-integers-function-to-print-integers-within-a-range) |
+| 151 | [What is tree shaking](#what-is-tree-shaking) |
+| 152 | [What is the need of tree shaking](#what-is-the-need-of-tree-shaking) |
+| 153 | [Is it recommended to use eval](#is-it-recommended-to-use-eval) |
+| 154 | [What is a Regular Expression](#what-is-a-regular-expression) |
+| 155 | [What are the string methods that accept Regular expression](#what-are-the-string-methods-that-accept-regular-expression) |
+| 156 | [What are modifiers in regular expression](#what-are-modifiers-in-regular-expression) |
+| 157 | [What are regular expression patterns](#what-are-regular-expression-patterns) |
+| 158 | [What is a RegExp object](#what-is-a-regexp-object) |
+| 159 | [How do you search a string for a pattern](#how-do-you-search-a-string-for-a-pattern) |
+| 160 | [What is the purpose of exec method](#what-is-the-purpose-of-exec-method) |
+| 161 | [How do you change the style of a HTML element](#how-do-you-change-the-style-of-a-html-element) |
+| 162 | [What would be the result of 1+2+'3'](#what-would-be-the-result-of-123) |
+| 163 | [What is a debugger statement](#what-is-a-debugger-statement) |
+| 164 | [What is the purpose of breakpoints in debugging](#what-is-the-purpose-of-breakpoints-in-debugging) |
+| 165 | [Can I use reserved words as identifiers](#can-i-use-reserved-words-as-identifiers) |
+| 166 | [How do you detect a mobile browser](#how-do-you-detect-a-mobile-browser) |
+| 167 | [How do you detect a mobile browser without regexp](#how-do-you-detect-a-mobile-browser-without-regexp) |
+| 168 | [How do you get the image width and height using JS](#how-do-you-get-the-image-width-and-height-using-js) |
+| 169 | [How do you make synchronous HTTP request](#how-do-you-make-synchronous-http-request) |
+| 170 | [How do you make asynchronous HTTP request](#how-do-you-make-asynchronous-http-request) |
+| 171 | [How do you convert date to another timezone in javascript](#how-do-you-convert-date-to-another-timezone-in-javascript) |
+| 172 | [What are the properties used to get size of window](#what-are-the-properties-used-to-get-size-of-window) |
+| 173 | [What is a conditional operator in javascript](#what-is-a-conditional-operator-in-javascript) |
+| 174 | [Can you apply chaining on conditional operator](#can-you-apply-chaining-on-conditional-operator) |
+| 175 | [What are the ways to execute javascript after a page load](#what-are-the-ways-to-execute-javascript-after-a-page-load) |
+| 176 | [What is the difference between proto and prototype](#what-is-the-difference-between-proto-and-prototype) |
+| 177 | [Can you give an example of when you really need a semicolon](#can-you-give-an-example-of-when-you-really-need-a-semicolon) |
+| 178 | [What is the freeze method](#what-is-the-freeze-method) |
+| 179 | [What is the purpose of the freeze method](#what-is-the-purpose-of-the-freeze-method) |
+| 180 | [Why do I need to use the freeze method](#why-do-i-need-to-use-the-freeze-method) |
+| 181 | [How do you detect a browser language preference](#how-do-you-detect-a-browser-language-preference) |
+| 182 | [How to convert a string to title case with javascript](#how-to-convert-a-string-to-title-case-with-javascript) |
+| 183 | [How do you detect if javascript is disabled on the page](#how-do-you-detect-if-javascript-is-disabled-on-the-page) |
+| 184 | [What are various operators supported by javascript](#what-are-various-operators-supported-by-javascript) |
+| 185 | [What is a rest parameter](#what-is-a-rest-parameter) |
+| 186 | [What happens if you do not use rest parameter as a last argument](#what-happens-if-you-do-not-use-rest-parameter-as-a-last-argument) |
+| 187 | [What are the bitwise operators available in javascript](#what-are-the-bitwise-operators-available-in-javascript) |
+| 188 | [What is a spread operator](#what-is-a-spread-operator) |
+| 189 | [How do you determine whether object is frozen or not](#how-do-you-determine-whether-object-is-frozen-or-not) |
+| 190 | [How do you determine two values same or not using object](#how-do-you-determine-two-values-same-or-not-using-object) |
+| 191 | [What is the purpose of using object is method](#what-is-the-purpose-of-using-object-is-method) |
+| 192 | [How do you copy properties from one object to other](#how-do-you-copy-properties-from-one-object-to-other) |
+| 193 | [What are the applications of the assign method](#what-are-the-applications-of-the-assign-method) |
+| 194 | [What is a proxy object](#what-is-a-proxy-object) |
+| 195 | [What is the purpose of the seal method](#what-is-the-purpose-of-the-seal-method) |
+| 196 | [What are the applications of the seal method](#what-are-the-applications-of-the-seal-method) |
+| 197 | [What are the differences between the freeze and seal methods](#what-are-the-differences-between-the-freeze-and-seal-methods) |
+| 198 | [How do you determine if an object is sealed or not](#how-do-you-determine-if-an-object-is-sealed-or-not) |
+| 199 | [How do you get enumerable key and value pairs](#how-do-you-get-enumerable-key-and-value-pairs) |
+| 200 | [What is the main difference between Object.values and Object.entries method](#what-is-the-main-difference-between-objectvalues-and-objectentries-method) |
+| 201 | [How can you get the list of keys of any object](#how-can-you-get-the-list-of-keys-of-any-object) |
+| 202 | [How do you create an object with a prototype](#how-do-you-create-an-object-with-a-prototype) |
+| 203 | [What is a WeakSet](#what-is-a-weakset) |
+| 204 | [What are the differences between WeakSet and Set](#what-are-the-differences-between-weakset-and-set) |
+| 205 | [List down the collection of methods available on WeakSet](#list-down-the-collection-of-methods-available-on-weakset) |
+| 206 | [What is a WeakMap](#what-is-a-weakmap) |
+| 207 | [What are the differences between WeakMap and Map](#what-are-the-differences-between-weakmap-and-map) |
+| 208 | [List down the collection of methods available on WeakMap](#list-down-the-collection-of-methods-available-on-weakmap) |
+| 209 | [What is the purpose of uneval](#what-is-the-purpose-of-uneval) |
+| 210 | [How do you encode an URL](#how-do-you-encode-an-url) |
+| 211 | [How do you decode an URL](#how-do-you-decode-an-url) |
+| 212 | [How do you print the contents of web page](#how-do-you-print-the-contents-of-web-page) |
+| 213 | [What is the difference between uneval and eval](#what-is-the-difference-between-uneval-and-eval) |
+| 214 | [What is an anonymous function](#what-is-an-anonymous-function) |
+| 215 | [What is the precedence order between local and global variables](#what-is-the-precedence-order-between-local-and-global-variables) |
+| 216 | [What are javascript accessors](#what-are-javascript-accessors) |
+| 217 | [How do you define property on Object constructor](#how-do-you-define-property-on-object-constructor) |
+| 218 | [What is the difference between get and defineProperty](#what-is-the-difference-between-get-and-defineproperty) |
+| 219 | [What are the advantages of Getters and Setters](#what-are-the-advantages-of-getters-and-setters) |
+| 220 | [Can I add getters and setters using defineProperty method](#can-i-add-getters-and-setters-using-defineproperty-method) |
+| 221 | [What is the purpose of switch-case](#what-is-the-purpose-of-switch-case) |
+| 222 | [What are the conventions to be followed for the usage of switch case](#what-are-the-conventions-to-be-followed-for-the-usage-of-switch-case) |
+| 223 | [What are primitive data types](#what-are-primitive-data-types) |
+| 224 | [What are the different ways to access object properties](#what-are-the-different-ways-to-access-object-properties) |
+| 225 | [What are the function parameter rules](#what-are-the-function-parameter-rules) |
+| 226 | [What is an error object](#what-is-an-error-object) |
+| 227 | [When do you get a syntax error](#when-do-you-get-a-syntax-error) |
+| 228 | [What are the different error names from error object](#what-are-the-different-error-names-from-error-object) |
+| 229 | [What are the various statements in error handling](#what-are-the-various-statements-in-error-handling) |
+| 230 | [What are the two types of loops in javascript](#what-are-the-two-types-of-loops-in-javascript) |
+| 231 | [What is nodejs](#what-is-nodejs) |
+| 232 | [What is the Intl object](#what-is-the-intl-object) |
+| 233 | [How do you perform language specific date and time formatting](#how-do-you-perform-language-specific-date-and-time-formatting) |
+| 234 | [What is an Iterator](#what-is-an-iterator) |
+| 235 | [How does synchronous iteration works](#how-does-synchronous-iteration-works) |
+| 236 | [What is the event loop](#what-is-the-event-loop) |
+| 237 | [What is the call stack](#what-is-the-call-stack) |
+| 238 | [What is the event queue](#what-is-the-event-queue) |
+| 239 | [What is a decorator](#what-is-a-decorator) |
+| 240 | [What are the properties of the Intl object](#what-are-the-properties-of-the-intl-object) |
+| 241 | [What is an Unary operator](#what-is-an-unary-operator) |
+| 242 | [How do you sort elements in an array](#how-do-you-sort-elements-in-an-array) |
+| 243 | [What is the purpose of compareFunction while sorting arrays](#what-is-the-purpose-of-comparefunction-while-sorting-arrays) |
+| 244 | [How do you reverse an array](#how-do-you-reverse-an-array) |
+| 245 | [How do you find the min and max values in an array](#how-do-you-find-the-min-and-max-values-in-an-array) |
+| 246 | [How do you find the min and max values without Math functions](#how-do-you-find-the-min-and-max-values-without-math-functions) |
+| 247 | [What is an empty statement and purpose of it](#what-is-an-empty-statement-and-purpose-of-it) |
+| 248 | [How do you get the metadata of a module](#how-do-you-get-the-metadata-of-a-module) |
+| 249 | [What is the comma operator](#what-is-the-comma-operator) |
+| 250 | [What is the advantage of the comma operator](#what-is-the-advantage-of-the-comma-operator) |
+| 251 | [What is typescript](#what-is-typescript) |
+| 252 | [What are the differences between javascript and typescript](#what-are-the-differences-between-javascript-and-typescript) |
+| 253 | [What are the advantages of typescript over javascript](#what-are-the-advantages-of-typescript-over-javascript) |
+| 254 | [What is an object initializer](#what-is-an-object-initializer) |
+| 255 | [What is a constructor method](#what-is-a-constructor-method) |
+| 256 | [What happens if you write constructor more than once in a class](#what-happens-if-you-write-constructor-more-than-once-in-a-class) |
+| 257 | [How do you call the constructor of a parent class](#how-do-you-call-the-constructor-of-a-parent-class) |
+| 258 | [How do you get the prototype of an object](#how-do-you-get-the-prototype-of-an-object) |
+| 259 | [What happens If I pass string type for getPrototype method](#what-happens-if-i-pass-string-type-for-getprototype-method) |
+| 260 | [How do you set the prototype of one object to another](#how-do-you-set-the-prototype-of-one-object-to-another) |
+| 261 | [How do you check whether an object can be extended or not](#how-do-you-check-whether-an-object-can-be-extended-or-not) |
+| 262 | [How do you prevent an object from being extend](#how-do-you-prevent-an-object-from-being-extend) |
+| 263 | [What are the different ways to make an object non-extensible](#what-are-the-different-ways-to-make-an-object-non-extensible) |
+| 264 | [How do you define multiple properties on an object](#how-do-you-define-multiple-properties-on-an-object) |
+| 265 | [What is the MEAN stack](#what-is-the-mean-stack) |
+| 266 | [What Is Obfuscation in javascript](#what-is-obfuscation-in-javascript) |
+| 267 | [Why do you need Obfuscation](#why-do-you-need-obfuscation) |
+| 268 | [What is Minification](#what-is-minification) |
+| 269 | [What are the advantages of minification](#what-are-the-advantages-of-minification) |
+| 270 | [What are the differences between Obfuscation and Encryption](#what-are-the-differences-between-obfuscation-and-encryption) |
+| 271 | [What are the common tools used for minification](#what-are-the-common-tools-used-for-minification) |
+| 272 | [How do you perform form validation using javascript](#how-do-you-perform-form-validation-using-javascript) |
+| 273 | [How do you perform form validation without javascript](#how-do-you-perform-form-validation-without-javascript) |
+| 274 | [What are the DOM methods available for constraint validation](#what-are-the-dom-methods-available-for-constraint-validation) |
+| 275 | [What are the available constraint validation DOM properties](#what-are-the-available-constraint-validation-dom-properties) |
+| 276 | [What are the validity properties](#what-are-the-validity-properties) |
+| 277 | [Give an example usage of the rangeOverflow property](#give-an-example-usage-of-the-rangeoverflow-property) |
+| 278 | [Are enums available in javascript](#are-enums-available-in-javascript) |
+| 279 | [What is an enum](#what-is-an-enum) |
+| 280 | [How do you list all properties of an object](#how-do-you-list-all-properties-of-an-object) |
+| 281 | [How do you get property descriptors of an object](#how-do-you-get-property-descriptors-of-an-object) |
+| 282 | [What are the attributes provided by a property descriptor](#what-are-the-attributes-provided-by-a-property-descriptor) |
+| 283 | [How do you extend classes](#how-do-you-extend-classes) |
+| 284 | [How do I modify the url without reloading the page](#how-do-i-modify-the-url-without-reloading-the-page) |
+| 285 | [How do you check whether or not an array includes a particular value](#how-do-you-check-whether-or-not-an-array-includes-a-particular-value) |
+| 286 | [How do you compare scalar arrays](#how-do-you-compare-scalar-arrays) |
+| 287 | [How to get the value from get parameters](#how-to-get-the-value-from-get-parameters) |
+| 288 | [How do you print numbers with commas as thousand separators](#how-do-you-print-numbers-with-commas-as-thousand-separators) |
+| 289 | [What is the difference between java and javascript](#what-is-the-difference-between-java-and-javascript) |
+| 290 | [Does JavaScript support namespaces](#does-javascript-support-namespaces) |
+| 291 | [How do you declare a namespace](#how-do-you-declare-a-namespace) |
+| 292 | [How do you invoke javascript code in an iframe from the parent page](#how-do-you-invoke-javascript-code-in-an-iframe-from-the-parent-page) |
+| 293 | [How do you get the timezone offset of a date object](#how-do-you-get-the-timezone-offset-of-a-date-object) |
+| 294 | [How do you load CSS and JS files dynamically](#how-do-you-load-css-and-js-files-dynamically) |
+| 295 | [What are the different methods to find HTML elements in DOM](#what-are-the-different-methods-to-find-html-elements-in-dom) |
+| 296 | [What is jQuery](#what-is-jquery) |
+| 297 | [What is V8 JavaScript engine](#what-is-v8-javascript-engine) |
+| 298 | [Why do we call javascript as dynamic language](#why-do-we-call-javascript-as-dynamic-language) |
+| 299 | [What is a void operator](#what-is-a-void-operator) |
+| 300 | [How to set the cursor to wait](#how-to-set-the-cursor-to-wait) |
+| 301 | [How do you create an infinite loop](#how-do-you-create-an-infinite-loop) |
+| 302 | [Why do you need to avoid with statement](#why-do-you-need-to-avoid-with-statement) |
+| 303 | [What is the output of the following for loops](#what-is-the-output-of-the-following-for-loops) |
+| 304 | [List down some of the features of ES6](#list-down-some-of-the-features-of-es6) |
+| 305 | [What is ES6](#what-is-es6) |
+| 306 | [Can I redeclare let and const variables](#can-i-redeclare-let-and-const-variables) |
+| 307 | [Does the `const` variable make the value immutable](#does-the-const-variable-make-the-value-immutable) |
+| 308 | [What are default parameters](#what-are-default-parameters) |
+| 309 | [What are template literals](#what-are-template-literals) |
+| 310 | [How do you write multi-line strings in template literals](#how-do-you-write-multi-line-strings-in-template-literals) |
+| 311 | [What are nesting templates](#what-are-nesting-templates) |
+| 312 | [What are tagged templates](#what-are-tagged-templates) |
+| 313 | [What are raw strings](#what-are-raw-strings) |
+| 314 | [What is destructuring assignment](#what-is-destructuring-assignment) |
+| 315 | [What are default values in destructuring assignment](#what-are-default-values-in-destructuring-assignment) |
+| 316 | [How do you swap variables in destructuring assignment](#how-do-you-swap-variables-in-destructuring-assignment) |
+| 317 | [What are enhanced object literals](#what-are-enhanced-object-literals) |
+| 318 | [What are dynamic imports](#what-are-dynamic-imports) |
+| 319 | [What are the use cases for dynamic imports](#what-are-the-use-cases-for-dynamic-imports) |
+| 320 | [What are typed arrays](#what-are-typed-arrays) |
+| 321 | [What are the advantages of module loaders](#what-are-the-advantages-of-module-loaders) |
+| 322 | [What is collation](#what-is-collation) |
+| 323 | [What is for...of statement](#what-is-forof-statement) |
+| 324 | [What is the output of below spread operator array](#what-is-the-output-of-below-spread-operator-array) |
+| 325 | [Is PostMessage secure](#is-postmessage-secure) |
+| 326 | [What are the problems with postmessage target origin as wildcard](#what-are-the-problems-with-postmessage-target-origin-as-wildcard) |
+| 327 | [How do you avoid receiving postMessages from attackers](#how-do-you-avoid-receiving-postmessages-from-attackers) |
+| 328 | [Can I avoid using postMessages completely](#can-i-avoid-using-postmessages-completely) |
+| 329 | [Is postMessages synchronous](#is-postmessages-synchronous) |
+| 330 | [What paradigm is Javascript](#what-paradigm-is-javascript) |
+| 331 | [What is the difference between internal and external javascript](#what-is-the-difference-between-internal-and-external-javascript) |
+| 332 | [Is JavaScript faster than server side script](#is-javascript-faster-than-server-side-script) |
+| 333 | [How do you get the status of a checkbox](#how-do-you-get-the-status-of-a-checkbox) |
+| 334 | [What is the purpose of double tilde operator](#what-is-the-purpose-of-double-tilde-operator) |
+| 335 | [How do you convert character to ASCII code](#how-do-you-convert-character-to-ascii-code) |
+| 336 | [What is ArrayBuffer](#what-is-arraybuffer) |
+| 337 | [What is the output of below string expression](#what-is-the-output-of-below-string-expression) |
+| 338 | [What is the purpose of Error object](#what-is-the-purpose-of-error-object) |
+| 339 | [What is the purpose of EvalError object](#what-is-the-purpose-of-evalerror-object) |
+| 340 | [What are the list of cases error thrown from non-strict mode to strict mode](#what-are-the-list-of-cases-error-thrown-from-non-strict-mode-to-strict-mode) |
+| 341 | [Do all objects have prototypes](#do-all-objects-have-prototypes) |
+| 342 | [What is the difference between a parameter and an argument](#what-is-the-difference-between-a-parameter-and-an-argument) |
+| 343 | [What is the purpose of some method in arrays](#what-is-the-purpose-of-some-method-in-arrays) |
+| 344 | [How do you combine two or more arrays](#how-do-you-combine-two-or-more-arrays) |
+| 345 | [What is the difference between Shallow and Deep copy](#what-is-the-difference-between-shallow-and-deep-copy) |
+| 346 | [How do you create specific number of copies of a string](#how-do-you-create-specific-number-of-copies-of-a-string) |
+| 347 | [How do you return all matching strings against a regular expression](#how-do-you-return-all-matching-strings-against-a-regular-expression) |
+| 348 | [How do you trim a string at the beginning or ending](#how-do-you-trim-a-string-at-the-beginning-or-ending) |
+| 349 | [What is the output of below console statement with unary operator](#what-is-the-output-of-below-console-statement-with-unary-operator) |
+| 350 | [Does javascript uses mixins](#does-javascript-uses-mixins) |
+| 351 | [What is a thunk function](#what-is-a-thunk-function) |
+| 352 | [What are asynchronous thunks](#what-are-asynchronous-thunks) |
+| 353 | [What is the output of below function calls](#what-is-the-output-of-below-function-calls) |
+| 354 | [How to remove all line breaks from a string](#how-to-remove-all-line-breaks-from-a-string) |
+| 355 | [What is the difference between reflow and repaint](#what-is-the-difference-between-reflow-and-repaint) |
+| 356 | [What happens with negating an array](#what-happens-with-negating-an-array) |
+| 357 | [What happens if we add two arrays](#what-happens-if-we-add-two-arrays) |
+| 358 | [What is the output of prepend additive operator on falsy values](#what-is-the-output-of-prepend-additive-operator-on-falsy-values) |
+| 359 | [How do you create self string using special characters](#how-do-you-create-self-string-using-special-characters) |
+| 360 | [How do you remove falsy values from an array](#how-do-you-remove-falsy-values-from-an-array) |
+| 361 | [How do you get unique values of an array](#how-do-you-get-unique-values-of-an-array) |
+| 362 | [What is destructuring aliases](#what-is-destructuring-aliases) |
+| 363 | [How do you map the array values without using map method](#how-do-you-map-the-array-values-without-using-map-method) |
+| 364 | [How do you empty an array](#how-do-you-empty-an-array) |
+| 365 | [How do you round numbers to certain decimals](#how-do-you-round-numbers-to-certain-decimals) |
+| 366 | [What is the easiest way to convert an array to an object](#what-is-the-easiest-way-to-convert-an-array-to-an-object) |
+| 367 | [How do you create an array with some data](#how-do-you-create-an-array-with-some-data) |
+| 368 | [What are the placeholders from console object](#what-are-the-placeholders-from-console-object) |
+| 369 | [Is it possible to add CSS to console messages](#is-it-possible-to-add-css-to-console-messages) |
+| 370 | [What is the purpose of dir method of console object](#what-is-the-purpose-of-dir-method-of-console-object) |
+| 371 | [Is it possible to debug HTML elements in console](#is-it-possible-to-debug-html-elements-in-console) |
+| 372 | [How do you display data in a tabular format using console object](#how-do-you-display-data-in-a-tabular-format-using-console-object) |
+| 373 | [How do you verify that an argument is a Number or not](#how-do-you-verify-that-an-argument-is-a-number-or-not) |
+| 374 | [How do you create copy to clipboard button](#how-do-you-create-copy-to-clipboard-button) |
+| 375 | [What is the shortcut to get timestamp](#what-is-the-shortcut-to-get-timestamp) |
+| 376 | [How do you flattening multi dimensional arrays](#how-do-you-flattening-multi-dimensional-arrays) |
+| 377 | [What is the easiest multi condition checking](#what-is-the-easiest-multi-condition-checking) |
+| 378 | [How do you capture browser back button](#how-do-you-capture-browser-back-button) |
+| 379 | [How do you disable right click in the web page](#how-do-you-disable-right-click-in-the-web-page) |
+| 380 | [What are wrapper objects](#what-are-wrapper-objects) |
+| 381 | [What is AJAX](#what-is-ajax) |
+| 382 | [What are the different ways to deal with Asynchronous Code](#what-are-the-different-ways-to-deal-with-asynchronous-code) |
+| 383 | [How to cancel a fetch request](#how-to-cancel-a-fetch-request) |
+| 384 | [What is web speech API](#what-is-web-speech-api) |
+| 385 | [What is minimum timeout throttling](#what-is-minimum-timeout-throttling) |
+| 386 | [How do you implement zero timeout in modern browsers](#how-do-you-implement-zero-timeout-in-modern-browsers) |
+| 387 | [What are tasks in event loop](#what-are-tasks-in-event-loop) |
+| 388 | [What is microtask](#what-is-microtask) |
+| 389 | [What are different event loops](#what-are-different-event-loops) |
+| 390 | [What is the purpose of queueMicrotask](#what-is-the-purpose-of-queuemicrotask) |
+| 391 | [How do you use javascript libraries in typescript file](#how-do-you-use-javascript-libraries-in-typescript-file) |
+| 392 | [What are the differences between promises and observables](#what-are-the-differences-between-promises-and-observables) |
+| 393 | [What is heap](#what-is-heap) |
+| 394 | [What is an event table](#what-is-an-event-table) |
+| 395 | [What is a microTask queue](#what-is-a-microtask-queue) |
+| 396 | [What is the difference between shim and polyfill](#what-is-the-difference-between-shim-and-polyfill) |
+| 397 | [How do you detect primitive or non primitive value type](#how-do-you-detect-primitive-or-non-primitive-value-type) |
+| 398 | [What is babel](#what-is-babel) |
+| 399 | [Is Node.js completely single threaded](#is-nodejs-completely-single-threaded) |
+| 400 | [What are the common use cases of observables](#what-are-the-common-use-cases-of-observables) |
+| 401 | [What is RxJS](#what-is-rxjs) |
| 402 | [What is the difference between Function constructor and function declaration](#what-is-the-difference-between-function-constructor-and-function-declaration) |
-| 403 | [What is a Short circuit condition](#what-is-a-short-circuit-condition) |
-| 404 | [What is the easiest way to resize an array](#what-is-the-easiest-way-to-resize-an-array) |
-| 405 | [What is an observable](#what-is-an-observable) |
-| 406 | [What is the difference between function and class declarations](#what-is-the-difference-between-function-and-class-declarations) |
-| 407 | [What is an async function](#what-is-an-async-function) |
-| 408 | [How do you prevent promises swallowing errors](#how-do-you-prevent-promises-swallowing-errors) |
-| 409 | [What is deno](#what-is-deno) |
-| 410 | [How do you make an object iterable in javascript](#how-do-you-make-an-object-iterable-in-javascript) |
-| 411 | [What is a Proper Tail Call](#what-is-a-proper-tail-call) |
-| 412 | [How do you check an object is a promise or not](#how-do-you-check-an-object-is-a-promise-or-not) |
-| 413 | [How to detect if a function is called as constructor](#how-to-detect-if-a-function-is-called-as-constructor) |
-| 414 | [What are the differences between arguments object and rest parameter](#what-are-the-differences-between-arguments-object-and-rest-parameter) |
-| 415 | [What are the differences between spread operator and rest parameter](#what-are-the-differences-between-spread-operator-and-rest-parameter) |
-| 416 | [What are the different kinds of generators](#what-are-the-different-kinds-of-generators) |
-| 417 | [What are the built-in iterables](#what-are-the-built-in-iterables) |
-| 418 | [What are the differences between for...of and for...in statements](#what-are-the-differences-between-forof-and-forin-statements) |
-| 419 | [How do you define instance and non-instance properties](#how-do-you-define-instance-and-non-instance-properties) |
-| 420 | [What is the difference between isNaN and Number.isNaN?](#what-is-the-difference-between-isnan-and-numberisnan) |
-| 421 | [How to invoke an IIFE without any extra brackets?](#how-to-invoke-an-iife-without-any-extra-brackets) |
-| 422 | [Is that possible to use expressions in switch cases?](#is-that-possible-to-use-expressions-in-switch-cases) |
-| 423 | [What is the easiest way to ignore promise errors?](#what-is-the-easiest-way-to-ignore-promise-errors) |
-| 424 | [How do style the console output using CSS?](#how-do-style-the-console-output-using-css) |
-| 425 | [What is nullish coalescing operator (??)?](#what-is-nullish-coalescing-operator-) |
-| 426 | [How do you group and nest console output?](#how-do-you-group-and-nest-console-output) |
-| 427 | [What is the difference between dense and sparse arrays?](#what-is-the-difference-between-dense-and-sparse-arrays) |
-| 428 | [What are the different ways to create sparse arrays?](#what-are-the-different-ways-to-create-sparse-arrays) |
-| 429 | [What is the difference between setTimeout, setImmediate and process.nextTick?](#what-is-the-difference-between-settimeout-setimmediate-and-processnexttick) |
-| 430 | [How do you reverse an array without modifying original array?](#how-do-you-reverse-an-array-without-modifying-original-array) |
-| 431 | [How do you create custom HTML element?](#how-do-you-create-custom-html-element) |
-| 432 | [What is global execution context?](#what-is-global-execution-context) |
-| 433 | [What is function execution context?](#what-is-function-execution-context) |
-| 434 | [What is debouncing?](#what-is-debouncing) |
-| 435 | [What is throttling?](#what-is-throttling) |
-| 436 | [What is optional chaining?](#what-is-optional-chaining) |
-| 437 | [What is an environment record?](#what-is-an-environment-record) |
-| 438 | [How to verify if a variable is an array?](#how-to-verify-if-a-variable-is-an-array) |
-| 439 | [What is pass by value and pass by reference?](#what-is-pass-by-value-and-pass-by-reference) |
-| 440 | [What are the differences between primitives and non-primitives?](#what-are-the-differences-between-primitives-and-non-primitives) |
-| 441 | [How do you create your own bind method using either call or apply method?](#how-do-you-create-your-own-bind-method-using-either-call-or-apply-method) |
-| 442 | [What are the differences between pure and impure functions?](#what-are-the-differences-between-pure-and-impure-functions) |
-| 443 | [What is referential transparency?](#what-is-referential-transparency) |
-| 444 | [What are the possible side-effects in javascript?](#what-are-the-possible-side-effects-in-javascript) |
-| 445 | [What are compose and pipe functions?](#what-are-compose-and-pipe-functions) |
-| 446 | [What is module pattern?](#what-is-module-pattern) |
-| 447 | [What is Function Composition?](#what-is-function-composition) |
-| 448 | [How to use await outside of async function prior to ES2022?](#how-to-use-await-outside-of-async-function-prior-to-es2022) |
-| 449 | [What is the purpose of the this keyword in JavaScript?](#what-is-the-purpose-of-the-this-keyword-in-javascript) |
-| 450 | [What are the uses of closures?](#what-are-the-uses-of-closures) |
-| 451 | [What are the phases of execution context?](#what-are-the-phases-of-execution-context) |
-| 452 | [What are the possible reasons for memory leaks?](#what-are-the-possible-reasons-for-memory-leaks) |
-| 453 | [What are the optimization techniques of V8 engine?](#what-are-the-optimization-techniques-of-v8-engine) |
-| 454 | [What are the examples of built-in higher order functions?](#what-are-the-examples-of-built-in-higher-order-functions) |
-| 455 | [What are the benefits higher order functions?](#what-are-the-benefits-higher-order-functions) |
-| 456 | [How do you create polyfills for map, filter and reduce methods?](#how-do-you-create-polyfills-for-map-filter-and-reduce-methods) |
-| 457 | [What is the difference between map and forEach functions?](#what-is-the-difference-between-map-and-foreach-functions) |
-| 458 | [Give an example of statements affected by automatic semicolon insertion?](#give-an-example-of-statements-affected-by-automatic-semicolon-insertion) |
-| 459 | [What are the event phases of a browser?](#what-are-the-event-phases-of-a-browser) |
-| 460 | [What are the real world use cases of proxy?](#what-are-the-real-world-use-cases-of-proxy) |
-| 461 | [What are hidden classes?](#what-are-hidden-classes) |
-| 462 | [What is inline caching?](#what-is-inline-caching) |
-| 463 | [What are the different ways to execute external scripts?](#what-are-the-different-ways-to-execute-external-scripts) |
-| 464 | [What is Lexical Scope?](#what-is-lexical-scope) |
-| 465 | [How to detect system dark mode in javascript?](#how-to-detect-system-dark-mode-in-javascript) |
-| 466 | [What is the purpose of requestAnimationFrame method?](#what-is-the-purpose-of-requestanimationframe-method) |
-| 467 | [What is the difference between substring and substr methods?](#what-is-the-difference-between-substring-and-substr-methods) |
-| 468 | [How to find the number of parameters expected by a function?](#how-to-find-the-number-of-parameters-expected-by-a-function) |
-| 469 | [What is globalThis, and what is the importance of it?](#what-is-globalthis-and-what-is-the-importance-of-it) |
-| 470 | [What are the array mutation methods?](#what-are-the-array-mutation-methods) |
-| 471 | [What is module scope in JavaScript?](#what-is-module-scope-in-javascript) |
+| 403 | [What is a Short circuit condition](#what-is-a-short-circuit-condition) |
+| 404 | [What is the easiest way to resize an array](#what-is-the-easiest-way-to-resize-an-array) |
+| 405 | [What is an observable](#what-is-an-observable) |
+| 406 | [What is the difference between function and class declarations](#what-is-the-difference-between-function-and-class-declarations) |
+| 407 | [What is an async function](#what-is-an-async-function) |
+| 408 | [How do you prevent promises swallowing errors](#how-do-you-prevent-promises-swallowing-errors) |
+| 409 | [What is deno](#what-is-deno) |
+| 410 | [How do you make an object iterable in javascript](#how-do-you-make-an-object-iterable-in-javascript) |
+| 411 | [What is a Proper Tail Call](#what-is-a-proper-tail-call) |
+| 412 | [How do you check an object is a promise or not](#how-do-you-check-an-object-is-a-promise-or-not) |
+| 413 | [How to detect if a function is called as constructor](#how-to-detect-if-a-function-is-called-as-constructor) |
+| 414 | [What are the differences between arguments object and rest parameter](#what-are-the-differences-between-arguments-object-and-rest-parameter) |
+| 415 | [What are the differences between spread operator and rest parameter](#what-are-the-differences-between-spread-operator-and-rest-parameter) |
+| 416 | [What are the different kinds of generators](#what-are-the-different-kinds-of-generators) |
+| 417 | [What are the built-in iterables](#what-are-the-built-in-iterables) |
+| 418 | [What are the differences between for...of and for...in statements](#what-are-the-differences-between-forof-and-forin-statements) |
+| 419 | [How do you define instance and non-instance properties](#how-do-you-define-instance-and-non-instance-properties) |
+| 420 | [What is the difference between isNaN and Number.isNaN?](#what-is-the-difference-between-isnan-and-numberisnan) |
+| 421 | [How to invoke an IIFE without any extra brackets?](#how-to-invoke-an-iife-without-any-extra-brackets) |
+| 422 | [Is that possible to use expressions in switch cases?](#is-that-possible-to-use-expressions-in-switch-cases) |
+| 423 | [What is the easiest way to ignore promise errors?](#what-is-the-easiest-way-to-ignore-promise-errors) |
+| 424 | [How do style the console output using CSS?](#how-do-style-the-console-output-using-css) |
+| 425 | [What is nullish coalescing operator (??)?](#what-is-nullish-coalescing-operator-) |
+| 426 | [How do you group and nest console output?](#how-do-you-group-and-nest-console-output) |
+| 427 | [What is the difference between dense and sparse arrays?](#what-is-the-difference-between-dense-and-sparse-arrays) |
+| 428 | [What are the different ways to create sparse arrays?](#what-are-the-different-ways-to-create-sparse-arrays) |
+| 429 | [What is the difference between setTimeout, setImmediate and process.nextTick?](#what-is-the-difference-between-settimeout-setimmediate-and-processnexttick) |
+| 430 | [How do you reverse an array without modifying original array?](#how-do-you-reverse-an-array-without-modifying-original-array) |
+| 431 | [How do you create custom HTML element?](#how-do-you-create-custom-html-element) |
+| 432 | [What is global execution context?](#what-is-global-execution-context) |
+| 433 | [What is function execution context?](#what-is-function-execution-context) |
+| 434 | [What is debouncing?](#what-is-debouncing) |
+| 435 | [What is throttling?](#what-is-throttling) |
+| 436 | [What is optional chaining?](#what-is-optional-chaining) |
+| 437 | [What is an environment record?](#what-is-an-environment-record) |
+| 438 | [How to verify if a variable is an array?](#how-to-verify-if-a-variable-is-an-array) |
+| 439 | [What is pass by value and pass by reference?](#what-is-pass-by-value-and-pass-by-reference) |
+| 440 | [What are the differences between primitives and non-primitives?](#what-are-the-differences-between-primitives-and-non-primitives) |
+| 441 | [How do you create your own bind method using either call or apply method?](#how-do-you-create-your-own-bind-method-using-either-call-or-apply-method) |
+| 442 | [What are the differences between pure and impure functions?](#what-are-the-differences-between-pure-and-impure-functions) |
+| 443 | [What is referential transparency?](#what-is-referential-transparency) |
+| 444 | [What are the possible side-effects in javascript?](#what-are-the-possible-side-effects-in-javascript) |
+| 445 | [What are compose and pipe functions?](#what-are-compose-and-pipe-functions) |
+| 446 | [What is module pattern?](#what-is-module-pattern) |
+| 447 | [What is Function Composition?](#what-is-function-composition) |
+| 448 | [How to use await outside of async function prior to ES2022?](#how-to-use-await-outside-of-async-function-prior-to-es2022) |
+| 449 | [What is the purpose of the this keyword in JavaScript?](#what-is-the-purpose-of-the-this-keyword-in-javascript) |
+| 450 | [What are the uses of closures?](#what-are-the-uses-of-closures) |
+| 451 | [What are the phases of execution context?](#what-are-the-phases-of-execution-context) |
+| 452 | [What are the possible reasons for memory leaks?](#what-are-the-possible-reasons-for-memory-leaks) |
+| 453 | [What are the optimization techniques of V8 engine?](#what-are-the-optimization-techniques-of-v8-engine) |
+| 454 | [What are the examples of built-in higher order functions?](#what-are-the-examples-of-built-in-higher-order-functions) |
+| 455 | [What are the benefits higher order functions?](#what-are-the-benefits-higher-order-functions) |
+| 456 | [How do you create polyfills for map, filter and reduce methods?](#how-do-you-create-polyfills-for-map-filter-and-reduce-methods) |
+| 457 | [What is the difference between map and forEach functions?](#what-is-the-difference-between-map-and-foreach-functions) |
+| 458 | [Give an example of statements affected by automatic semicolon insertion?](#give-an-example-of-statements-affected-by-automatic-semicolon-insertion) |
+| 459 | [What are the event phases of a browser?](#what-are-the-event-phases-of-a-browser) |
+| 460 | [What are the real world use cases of proxy?](#what-are-the-real-world-use-cases-of-proxy) |
+| 461 | [What are hidden classes?](#what-are-hidden-classes) |
+| 462 | [What is inline caching?](#what-is-inline-caching) |
+| 463 | [What are the different ways to execute external scripts?](#what-are-the-different-ways-to-execute-external-scripts) |
+| 464 | [What is Lexical Scope?](#what-is-lexical-scope) |
+| 465 | [How to detect system dark mode in javascript?](#how-to-detect-system-dark-mode-in-javascript) |
+| 466 | [What is the purpose of requestAnimationFrame method?](#what-is-the-purpose-of-requestanimationframe-method) |
+| 467 | [What is the difference between substring and substr methods?](#what-is-the-difference-between-substring-and-substr-methods) |
+| 468 | [How to find the number of parameters expected by a function?](#how-to-find-the-number-of-parameters-expected-by-a-function) |
+| 469 | [What is globalThis, and what is the importance of it?](#what-is-globalthis-and-what-is-the-importance-of-it) |
+| 470 | [What are the array mutation methods?](#what-are-the-array-mutation-methods) |
+| 471 | [What is module scope in JavaScript?](#what-is-module-scope-in-javascript) |
+
-1. ### What are the possible ways to create objects in JavaScript
- There are many ways to create objects in javascript as mentioned below:
+1. ### What are the possible ways to create objects in JavaScript
- 1. **Object literal syntax:**
+ There are many ways to create objects in javascript as mentioned below:
- The object literal syntax (or object initializer), is a comma-separated set of name-value pairs wrapped in curly braces.
+ 1. **Object literal syntax:**
- ```javascript
- var object = {
- name: "Sudheer",
- age: 34
- };
- ```
+ The object literal syntax (or object initializer), is a comma-separated set of name-value pairs wrapped in curly braces.
- Object literal property values can be of any data type, including array, function, and nested object.
+ ```javascript
+ var object = {
+ name: "Sudheer",
+ age: 34,
+ };
+ ```
- **Note:** This is one of the easiest ways to create an object.
+ Object literal property values can be of any data type, including array, function, and nested object.
- 2. **Object constructor:**
+ **Note:** This is one of the easiest ways to create an object.
- The simplest way to create an empty object is using the `Object` constructor. Currently this approach is not recommended.
+ 2. **Object constructor:**
- ```javascript
- var object = new Object();
- ```
+ The simplest way to create an empty object is using the `Object` constructor. Currently this approach is not recommended.
- The `Object()` is a built-in constructor function so "new" keyword is not required. The above code snippet can be re-written as:
+ ```javascript
+ var object = new Object();
+ ```
- ```javascript
- var object = Object();
- ```
+ The `Object()` is a built-in constructor function so "new" keyword is not required. The above code snippet can be re-written as:
- 3. **Object's create method:**
+ ```javascript
+ var object = Object();
+ ```
- The `create` method of Object is used to create a new object by passing the specified prototype object and properties as arguments, i.e., this pattern is helpful to create new objects based on existing objects.
- The second argument is optional and it is used to create properties on a newly created object.
+ 3. **Object's create method:**
- The following code creates a new empty object whose prototype is null.
+ The `create` method of Object is used to create a new object by passing the specified prototype object and properties as arguments, i.e., this pattern is helpful to create new objects based on existing objects.
+ The second argument is optional and it is used to create properties on a newly created object.
- ```javascript
- var object = Object.create(null);
- ```
- The following example creates an object along with additional new properties.
+ The following code creates a new empty object whose prototype is null.
- ```javascript
- let vehicle = {
- wheels: '4',
- fuelType: 'Gasoline',
- color: 'Green'
- }
- let carProps = {
- type: {
- value: 'Volkswagen'
- },
- model: {
- value: 'Golf'
- }
- }
+ ```javascript
+ var object = Object.create(null);
+ ```
- var car = Object.create(vehicle, carProps);
- console.log(car);
- ```
+ The following example creates an object along with additional new properties.
- 4. **Function constructor:**
+ ```javascript
+ let vehicle = {
+ wheels: "4",
+ fuelType: "Gasoline",
+ color: "Green",
+ };
+ let carProps = {
+ type: {
+ value: "Volkswagen",
+ },
+ model: {
+ value: "Golf",
+ },
+ };
- In this approach, create any function and apply the new operator to create object instances.
+ var car = Object.create(vehicle, carProps);
+ console.log(car);
+ ```
- ```javascript
- function Person(name) {
- this.name = name;
- this.age = 21;
- }
- var object = new Person("Sudheer");
- ```
+ 4. **Function constructor:**
- 5. **Function constructor with prototype:**
+ In this approach, create any function and apply the new operator to create object instances.
- This is similar to function constructor but it uses prototype for their properties and methods,
+ ```javascript
+ function Person(name) {
+ this.name = name;
+ this.age = 21;
+ }
+ var object = new Person("Sudheer");
+ ```
- ```javascript
- function Person() {}
- Person.prototype.name = "Sudheer";
- var object = new Person();
- ```
+ 5. **Function constructor with prototype:**
- This is equivalent to creating an instance with Object.create method with a function prototype and then calling that function with an instance and parameters as arguments.
+ This is similar to function constructor but it uses prototype for their properties and methods,
- ```javascript
- function func() {}
+ ```javascript
+ function Person() {}
+ Person.prototype.name = "Sudheer";
+ var object = new Person();
+ ```
- new func(x, y, z);
- ```
+ This is equivalent to creating an instance with Object.create method with a function prototype and then calling that function with an instance and parameters as arguments.
- **(OR)**
+ ```javascript
+ function func() {}
- ```javascript
- // Create a new instance using function prototype.
- var newInstance = Object.create(func.prototype)
+ new func(x, y, z);
+ ```
- // Call the function
- var result = func.call(newInstance, x, y, z),
+ **(OR)**
- // If the result is a non-null object then use it otherwise just use the new instance.
- console.log(result && typeof result === 'object' ? result : newInstance);
- ```
- 6. **Object's assign method:**
+ ```javascript
+ // Create a new instance using function prototype.
+ var newInstance = Object.create(func.prototype)
- The `Object.assign` method is used to copy all the properties from one or more source objects and stores them into a target object.
+ // Call the function
+ var result = func.call(newInstance, x, y, z),
- The following code creates a new staff object by copying properties of his working company and the car he owns.
+ // If the result is a non-null object then use it otherwise just use the new instance.
+ console.log(result && typeof result === 'object' ? result : newInstance);
+ ```
- ```javascript
- const orgObject = { company: 'XYZ Corp'};
- const carObject = { name: 'Toyota'};
- const staff = Object.assign({}, orgObject, carObject);
- ```
+ 6. **Object's assign method:**
- 7. **ES6 Class syntax:**
+ The `Object.assign` method is used to copy all the properties from one or more source objects and stores them into a target object.
- ES6 introduces class feature to create objects.
+ The following code creates a new staff object by copying properties of his working company and the car he owns.
- ```javascript
- class Person {
- constructor(name) {
- this.name = name;
- }
- }
+ ```javascript
+ const orgObject = { company: "XYZ Corp" };
+ const carObject = { name: "Toyota" };
+ const staff = Object.assign({}, orgObject, carObject);
+ ```
- var object = new Person("Sudheer");
- ```
+ 7. **ES6 Class syntax:**
- 8. **Singleton pattern:**
+ ES6 introduces class feature to create objects.
- A Singleton is an object which can only be instantiated one time. Repeated calls to its constructor return the same instance. This way one can ensure that they don't accidentally create multiple instances.
+ ```javascript
+ class Person {
+ constructor(name) {
+ this.name = name;
+ }
+ }
- ```javascript
- var object = new (function () {
- this.name = "Sudheer";
- })();
- ```
+ var object = new Person("Sudheer");
+ ```
- **[⬆ Back to Top](#table-of-contents)**
+ 8. **Singleton pattern:**
-2. ### What is a prototype chain
+ A Singleton is an object which can only be instantiated one time. Repeated calls to its constructor return the same instance. This way one can ensure that they don't accidentally create multiple instances.
+
+ ```javascript
+ var object = new (function () {
+ this.name = "Sudheer";
+ })();
+ ```
- **Prototype chaining** is used to build new types of objects based on existing ones. It is similar to inheritance in a class based language. i.e, When you create an object using a constructor function or a class, the created object inherits properties from a prototype object.
+ **[⬆ Back to Top](#table-of-contents)**
- The prototype on object instance is available through **Object.getPrototypeOf(object)** or **\_\_proto\_\_** property whereas prototype on constructor function is available through **Object.prototype**.
+2. ### What is a prototype chain
- 
+ **Prototype chaining** is used to build new types of objects based on existing ones. It is similar to inheritance in a class based language. i.e, When you create an object using a constructor function or a class, the created object inherits properties from a prototype object.
- **[⬆ Back to Top](#table-of-contents)**
+ The prototype on object instance is available through **Object.getPrototypeOf(object)** or **\_\_proto\_\_** property whereas prototype on constructor function is available through **Object.prototype**.
-3. ### What is the difference between Call, Apply and Bind
+ 
- The difference between Call, Apply and Bind can be explained with below examples,
+ **[⬆ Back to Top](#table-of-contents)**
- **Call:** The call() method invokes a function with a given `this` value and arguments provided one by one
+3. ### What is the difference between Call, Apply and Bind
- ```javascript
- var employee1 = { firstName: "John", lastName: "Rodson" };
- var employee2 = { firstName: "Jimmy", lastName: "Baily" };
+ The difference between Call, Apply and Bind can be explained with below examples,
- function invite(greeting1, greeting2) {
- console.log(
- greeting1 + " " + this.firstName + " " + this.lastName + ", " + greeting2
- );
- }
+ **Call:** The call() method invokes a function with a given `this` value and arguments provided one by one
- invite.call(employee1, "Hello", "How are you?"); // Hello John Rodson, How are you?
- invite.call(employee2, "Hello", "How are you?"); // Hello Jimmy Baily, How are you?
- ```
+ ```javascript
+ var employee1 = { firstName: "John", lastName: "Rodson" };
+ var employee2 = { firstName: "Jimmy", lastName: "Baily" };
- **Apply:** Invokes the function with a given `this` value and allows you to pass in arguments as an array
+ function invite(greeting1, greeting2) {
+ console.log(
+ greeting1 +
+ " " +
+ this.firstName +
+ " " +
+ this.lastName +
+ ", " +
+ greeting2
+ );
+ }
- ```javascript
- var employee1 = { firstName: "John", lastName: "Rodson" };
- var employee2 = { firstName: "Jimmy", lastName: "Baily" };
+ invite.call(employee1, "Hello", "How are you?"); // Hello John Rodson, How are you?
+ invite.call(employee2, "Hello", "How are you?"); // Hello Jimmy Baily, How are you?
+ ```
- function invite(greeting1, greeting2) {
- console.log(
- greeting1 + " " + this.firstName + " " + this.lastName + ", " + greeting2
- );
- }
+ **Apply:** Invokes the function with a given `this` value and allows you to pass in arguments as an array
- invite.apply(employee1, ["Hello", "How are you?"]); // Hello John Rodson, How are you?
- invite.apply(employee2, ["Hello", "How are you?"]); // Hello Jimmy Baily, How are you?
- ```
+ ```javascript
+ var employee1 = { firstName: "John", lastName: "Rodson" };
+ var employee2 = { firstName: "Jimmy", lastName: "Baily" };
- **Bind:** returns a new function, allowing you to pass any number of arguments
+ function invite(greeting1, greeting2) {
+ console.log(
+ greeting1 +
+ " " +
+ this.firstName +
+ " " +
+ this.lastName +
+ ", " +
+ greeting2
+ );
+ }
- ```javascript
- var employee1 = { firstName: "John", lastName: "Rodson" };
- var employee2 = { firstName: "Jimmy", lastName: "Baily" };
+ invite.apply(employee1, ["Hello", "How are you?"]); // Hello John Rodson, How are you?
+ invite.apply(employee2, ["Hello", "How are you?"]); // Hello Jimmy Baily, How are you?
+ ```
- function invite(greeting1, greeting2) {
- console.log(
- greeting1 + " " + this.firstName + " " + this.lastName + ", " + greeting2
- );
- }
+ **Bind:** returns a new function, allowing you to pass any number of arguments
- var inviteEmployee1 = invite.bind(employee1);
- var inviteEmployee2 = invite.bind(employee2);
- inviteEmployee1("Hello", "How are you?"); // Hello John Rodson, How are you?
- inviteEmployee2("Hello", "How are you?"); // Hello Jimmy Baily, How are you?
- ```
+ ```javascript
+ var employee1 = { firstName: "John", lastName: "Rodson" };
+ var employee2 = { firstName: "Jimmy", lastName: "Baily" };
- Call and Apply are pretty much interchangeable. Both execute the current function immediately. You need to decide whether it’s easier to send in an array or a comma separated list of arguments. You can remember by treating Call is for **comma** (separated list) and Apply is for **Array**.
+ function invite(greeting1, greeting2) {
+ console.log(
+ greeting1 +
+ " " +
+ this.firstName +
+ " " +
+ this.lastName +
+ ", " +
+ greeting2
+ );
+ }
- Bind creates a new function that will have `this` set to the first parameter passed to bind().
+ var inviteEmployee1 = invite.bind(employee1);
+ var inviteEmployee2 = invite.bind(employee2);
+ inviteEmployee1("Hello", "How are you?"); // Hello John Rodson, How are you?
+ inviteEmployee2("Hello", "How are you?"); // Hello Jimmy Baily, How are you?
+ ```
- **[⬆ Back to Top](#table-of-contents)**
+ Call and Apply are pretty much interchangeable. Both execute the current function immediately. You need to decide whether it’s easier to send in an array or a comma separated list of arguments. You can remember by treating Call is for **comma** (separated list) and Apply is for **Array**.
-4. ### What is JSON and its common operations
+ Bind creates a new function that will have `this` set to the first parameter passed to bind().
- **JSON** is a text-based data format following JavaScript object syntax, which was popularized by `Douglas Crockford`. It is useful when you want to transmit data across a network. It is basically just a text file with an extension of .json, and a MIME type of application/json
+ **[⬆ Back to Top](#table-of-contents)**
- **Parsing:** Converting a string to a native object
+4. ### What is JSON and its common operations
- ```javascript
- JSON.parse(text);
- ```
+ **JSON** is a text-based data format following JavaScript object syntax, which was popularized by `Douglas Crockford`. It is useful when you want to transmit data across a network. It is basically just a text file with an extension of .json, and a MIME type of application/json
- **Stringification:** Converting a native object to a string so that it can be transmitted across the network
+ **Parsing:** Converting a string to a native object
- ```javascript
- JSON.stringify(object);
- ```
+ ```javascript
+ JSON.parse(text);
+ ```
- **[⬆ Back to Top](#table-of-contents)**
+ **Stringification:** Converting a native object to a string so that it can be transmitted across the network
-5. ### What is the purpose of the array slice method
+ ```javascript
+ JSON.stringify(object);
+ ```
- The **slice()** method returns the selected elements in an array as a new array object. It selects the elements starting at the given start argument, and ends at the given optional end argument without including the last element. If you omit the second argument then it selects till the end of the array. This method can also accept negative index which counts back from the end of the array.
+ **[⬆ Back to Top](#table-of-contents)**
- Some of the examples of this method are,
+5. ### What is the purpose of the array slice method
- ```javascript
- let arrayIntegers = [1, 2, 3, 4, 5];
- let arrayIntegers1 = arrayIntegers.slice(0, 2); // returns [1,2]
- let arrayIntegers2 = arrayIntegers.slice(2, 3); // returns [3]
- let arrayIntegers3 = arrayIntegers.slice(4); //returns [5]
- let arrayIntegers4 = arrayIntegers.slice(-3, -1); //returns [3, 4]
- ```
+ The **slice()** method returns the selected elements in an array as a new array object. It selects the elements starting at the given start argument, and ends at the given optional end argument without including the last element. If you omit the second argument then it selects till the end of the array. This method can also accept negative index which counts back from the end of the array.
- **Note:** Slice method doesn't mutate the original array but it returns the subset as a new array.
+ Some of the examples of this method are,
- **[⬆ Back to Top](#table-of-contents)**
+ ```javascript
+ let arrayIntegers = [1, 2, 3, 4, 5];
+ let arrayIntegers1 = arrayIntegers.slice(0, 2); // returns [1,2]
+ let arrayIntegers2 = arrayIntegers.slice(2, 3); // returns [3]
+ let arrayIntegers3 = arrayIntegers.slice(4); //returns [5]
+ let arrayIntegers4 = arrayIntegers.slice(-3, -1); //returns [3, 4]
+ ```
-6. ### What is the purpose of the array splice method
+ **Note:** Slice method doesn't mutate the original array but it returns the subset as a new array.
- The **splice()** method adds/removes items to/from an array, and then returns the removed item. The first argument specifies the array position/index for insertion or deletion whereas the optional second argument indicates the number of elements to be deleted. Each additional argument is added to the array.
+ **[⬆ Back to Top](#table-of-contents)**
- Some of the examples of this method are:
+6. ### What is the purpose of the array splice method
- ```javascript
- let arrayIntegersOriginal1 = [1, 2, 3, 4, 5];
- let arrayIntegersOriginal2 = [1, 2, 3, 4, 5];
- let arrayIntegersOriginal3 = [1, 2, 3, 4, 5];
+ The **splice()** method adds/removes items to/from an array, and then returns the removed item. The first argument specifies the array position/index for insertion or deletion whereas the optional second argument indicates the number of elements to be deleted. Each additional argument is added to the array.
- let arrayIntegers1 = arrayIntegersOriginal1.splice(0, 2); // returns [1, 2]; original array: [3, 4, 5]
- let arrayIntegers2 = arrayIntegersOriginal2.splice(3); // returns [4, 5]; original array: [1, 2, 3]
- let arrayIntegers3 = arrayIntegersOriginal3.splice(3, 1, "a", "b", "c"); //returns [4]; original array: [1, 2, 3, "a", "b", "c", 5]
- ```
+ Some of the examples of this method are:
- **Note:** Splice method modifies the original array and returns the deleted array.
+ ```javascript
+ let arrayIntegersOriginal1 = [1, 2, 3, 4, 5];
+ let arrayIntegersOriginal2 = [1, 2, 3, 4, 5];
+ let arrayIntegersOriginal3 = [1, 2, 3, 4, 5];
+
+ let arrayIntegers1 = arrayIntegersOriginal1.splice(0, 2); // returns [1, 2]; original array: [3, 4, 5]
+ let arrayIntegers2 = arrayIntegersOriginal2.splice(3); // returns [4, 5]; original array: [1, 2, 3]
+ let arrayIntegers3 = arrayIntegersOriginal3.splice(3, 1, "a", "b", "c"); //returns [4]; original array: [1, 2, 3, "a", "b", "c", 5]
+ ```
- **[⬆ Back to Top](#table-of-contents)**
+ **Note:** Splice method modifies the original array and returns the deleted array.
-7. ### What is the difference between slice and splice
+ **[⬆ Back to Top](#table-of-contents)**
- Some of the major differences in a tabular form:
+7. ### What is the difference between slice and splice
- | Slice | Splice |
- | -------------------------------------------- | ----------------------------------------------- |
- | Doesn't modify the original array(immutable) | Modifies the original array(mutable) |
- | Returns the subset of original array | Returns the deleted elements as array |
- | Used to pick the elements from array | Used to insert/delete elements to/from array |
+ Some of the major differences in a tabular form:
- **[⬆ Back to Top](#table-of-contents)**
+ | Slice | Splice |
+ | -------------------------------------------- | -------------------------------------------- |
+ | Doesn't modify the original array(immutable) | Modifies the original array(mutable) |
+ | Returns the subset of original array | Returns the deleted elements as array |
+ | Used to pick the elements from array | Used to insert/delete elements to/from array |
-8. ### How do you compare Object and Map
+ **[⬆ Back to Top](#table-of-contents)**
- **Objects** are similar to **Maps** in that both let you set keys to values, retrieve those values, delete keys, and detect whether something is stored at a key. Due to this reason, Objects have been used as Maps historically. But there are important differences that make using a Map preferable in certain cases:
+8. ### How do you compare Object and Map
- 1. The keys of an Object can be Strings and Symbols, whereas they can be any value for a Map, including functions, objects, and any primitive type.
- 2. The keys in a Map are ordered while keys added to Object are not. Thus, when iterating over it, a Map object returns keys in the order of insertion.
- 3. You can get the size of a Map easily with the size property, while the number of properties in an Object must be determined manually.
- 4. A Map is an iterable and can thus be directly iterated, whereas iterating over an Object requires obtaining its keys in some fashion and iterating over them.
- 5. An Object has a prototype, so there are default keys in an object that could collide with your keys if you're not careful. As of ES5 this can be bypassed by creating an object(which can be called a map) using `Object.create(null)`, but this practice is seldom done.
- 6. A Map may perform better in scenarios involving frequent addition and removal of key pairs.
+ **Objects** are similar to **Maps** in that both let you set keys to values, retrieve those values, delete keys, and detect whether something is stored at a key. Due to this reason, Objects have been used as Maps historically. But there are important differences that make using a Map preferable in certain cases:
- **[⬆ Back to Top](#table-of-contents)**
+ 1. The keys of an Object can be Strings and Symbols, whereas they can be any value for a Map, including functions, objects, and any primitive type.
+ 2. The keys in a Map are ordered while keys added to Object are not. Thus, when iterating over it, a Map object returns keys in the order of insertion.
+ 3. You can get the size of a Map easily with the size property, while the number of properties in an Object must be determined manually.
+ 4. A Map is an iterable and can thus be directly iterated, whereas iterating over an Object requires obtaining its keys in some fashion and iterating over them.
+ 5. An Object has a prototype, so there are default keys in an object that could collide with your keys if you're not careful. As of ES5 this can be bypassed by creating an object(which can be called a map) using `Object.create(null)`, but this practice is seldom done.
+ 6. A Map may perform better in scenarios involving frequent addition and removal of key pairs.
-9. ### What is the difference between == and === operators
+ **[⬆ Back to Top](#table-of-contents)**
- JavaScript provides both strict(===, !==) and type-converting(==, !=) equality comparison. The strict operators take type of variable in consideration, while non-strict operators make type correction/conversion based upon values of variables. The strict operators follow the below conditions for different types,
+9. ### What is the difference between == and === operators
- 1. Two strings are strictly equal when they have the same sequence of characters, same length, and same characters in corresponding positions.
- 2. Two numbers are strictly equal when they are numerically equal, i.e., having the same number value.
- There are two special cases in this,
- 1. NaN is not equal to anything, including NaN.
- 2. Positive and negative zeros are equal to one another.
- 3. Two Boolean operands are strictly equal if both are true or both are false.
- 4. Two objects are strictly equal if they refer to the same Object.
- 5. Null and Undefined types are not equal with ===, but equal with == .
- i.e, `null===undefined --> false`, but `null==undefined --> true`
+ JavaScript provides both strict(===, !==) and type-converting(==, !=) equality comparison. The strict operators take type of variable in consideration, while non-strict operators make type correction/conversion based upon values of variables. The strict operators follow the below conditions for different types,
- Some of the example which covers the above cases:
+ 1. Two strings are strictly equal when they have the same sequence of characters, same length, and same characters in corresponding positions.
+ 2. Two numbers are strictly equal when they are numerically equal, i.e., having the same number value.
+ There are two special cases in this,
+ 1. NaN is not equal to anything, including NaN.
+ 2. Positive and negative zeros are equal to one another.
+ 3. Two Boolean operands are strictly equal if both are true or both are false.
+ 4. Two objects are strictly equal if they refer to the same Object.
+ 5. Null and Undefined types are not equal with ===, but equal with == .
+ i.e, `null===undefined --> false`, but `null==undefined --> true`
- ```javascript
- 0 == false // true
- 0 === false // false
- 1 == "1" // true
- 1 === "1" // false
- null == undefined // true
- null === undefined // false
- '0' == false // true
- '0' === false // false
- NaN == NaN or NaN === NaN // false
- []==[] or []===[] //false, refer different objects in memory
- {}=={} or {}==={} //false, refer different objects in memory
- ```
+ Some of the example which covers the above cases:
- **[⬆ Back to Top](#table-of-contents)**
+ ```javascript
+ 0 == false // true
+ 0 === false // false
+ 1 == "1" // true
+ 1 === "1" // false
+ null == undefined // true
+ null === undefined // false
+ '0' == false // true
+ '0' === false // false
+ NaN == NaN or NaN === NaN // false
+ []==[] or []===[] //false, refer different objects in memory
+ {}=={} or {}==={} //false, refer different objects in memory
+ ```
+
+ **[⬆ Back to Top](#table-of-contents)**
10. ### What are lambda expressions or arrow functions
An arrow function is a shorter/concise syntax for a function expression and does not have its own **this, arguments, super, or new.target**. These functions are best suited for non-method functions, and they cannot be used as constructors.
Some of the examples of arrow functions are listed as below,
+
```javascript
const arrowFunc1 = (a, b) => a + b; // Multiple parameters
- const arrowFunc2 = a => a * 10; // Single parameter
- const arrowFunc3 = () => {} // no parameters
+ const arrowFunc2 = (a) => a * 10; // Single parameter
+ const arrowFunc3 = () => {}; // no parameters
```
**[⬆ Back to Top](#table-of-contents)**
@@ -896,9 +920,10 @@
const higherOrder = (ReturnFirstOrderFunc) => ReturnFirstOrderFunc();
higherOrder(firstOrderFunc);
```
+
You can also call the function which you are passing to higher order function as callback function.
- The higher order function is helpful to write the modular and reusable code.
+ The higher order function is helpful to write the modular and reusable code.
**[⬆ Back to Top](#table-of-contents)**
@@ -982,12 +1007,12 @@
You can list out the differences in a tabular format
- | var | let |
- | ----------------------------------------------------- | --------------------------- |
- | It has been available from the beginning of JavaScript | Introduced as part of ES6 |
- | It has function scope | It has block scope |
- | Variable declaration will be hoisted, initialized as undefined | Hoisted but not initialized |
- | It is possible to re-declare the variable in the same scope | It is not possible to re-declare the variable |
+ | var | let |
+ | -------------------------------------------------------------- | --------------------------------------------- |
+ | It has been available from the beginning of JavaScript | Introduced as part of ES6 |
+ | It has function scope | It has block scope |
+ | Variable declaration will be hoisted, initialized as undefined | Hoisted but not initialized |
+ | It is possible to re-declare the variable in the same scope | It is not possible to re-declare the variable |
Let's take an example to see the difference,
@@ -1050,7 +1075,7 @@
21. ### What is the Temporal Dead Zone
- The Temporal Dead Zone(TDZ) is a specific period or area of a block where a variable is inaccessible until it has been initialized with a value. This behavior in JavaScript that occurs when declaring a variable with the let and const keywords, but not with var. In ECMAScript 6, accessing a `let` or `const` variable before its declaration (within its scope) causes a ReferenceError.
+ The Temporal Dead Zone(TDZ) is a specific period or area of a block where a variable is inaccessible until it has been initialized with a value. This behavior in JavaScript that occurs when declaring a variable with the let and const keywords, but not with var. In ECMAScript 6, accessing a `let` or `const` variable before its declaration (within its scope) causes a ReferenceError.
Let's see this behavior with an example,
@@ -1314,7 +1339,7 @@
document.cookie = "username=John; expires=Sat, 8 Jun 2019 12:00:00 UTC";
```
- 1. By default, the cookie belongs to a current page. But you can tell the browser what path the cookie belongs to using a path parameter.
+ 2. By default, the cookie belongs to a current page. But you can tell the browser what path the cookie belongs to using a path parameter.
```javascript
document.cookie = "username=John; path=/services";
@@ -1340,14 +1365,14 @@
Below are some of the differences between cookie, local storage and session storage,
- | Feature | Cookie | Local storage | Session storage |
- | --------------------------------- | ---------------------------------- | ---------------- | ------------------- |
- | Accessed on client or server side | Both server-side & client-side. The `set-cookie` HTTP response header is used by server inorder to send it to user. | client-side only | client-side only |
- | Expiry | Manually configured using Expires option | Forever until deleted | until tab is closed |
- | SSL support | Supported | Not supported | Not supported |
- | Maximum data size | 4KB | 5 MB | 5MB |
- | Accessible from | Any window | Any window | Same tab |
- | Sent with requests | Yes | No | No |
+ | Feature | Cookie | Local storage | Session storage |
+ | --------------------------------- | ------------------------------------------------------------------------------------------------------------------- | --------------------- | ------------------- |
+ | Accessed on client or server side | Both server-side & client-side. The `set-cookie` HTTP response header is used by server inorder to send it to user. | client-side only | client-side only |
+ | Expiry | Manually configured using Expires option | Forever until deleted | until tab is closed |
+ | SSL support | Supported | Not supported | Not supported |
+ | Maximum data size | 4KB | 5 MB | 5MB |
+ | Accessible from | Any window | Any window | Same tab |
+ | Sent with requests | Yes | No | No |
**[⬆ Back to Top](#table-of-contents)**
@@ -1470,7 +1495,7 @@
Here postMessage() method is used to post a message back to the HTML page
- 1. Create a Web Worker Object: You can create a web worker object by checking for browser support. Let's name this file as web_worker_example.js
+ 2. Create a Web Worker Object: You can create a web worker object by checking for browser support. Let's name this file as web_worker_example.js
```javascript
if (typeof w == "undefined") {
@@ -1486,14 +1511,14 @@
};
```
- 1. Terminate a Web Worker:
+ 3. Terminate a Web Worker:
Web workers will continue to listen for messages (even after the external script is finished) until it is terminated. You can use the terminate() method to terminate listening to the messages.
```javascript
w.terminate();
```
- 1. Reuse the Web Worker: If you set the worker variable to undefined you can reuse the code
+ 4. Reuse the Web Worker: If you set the worker variable to undefined you can reuse the code
```javascript
w = undefined;
@@ -1827,7 +1852,7 @@
The delete operator is used to delete the property as well as its value.
```javascript
- var user = { firstName: "John", lastName:"Doe", age: 20 };
+ var user = { firstName: "John", lastName: "Doe", age: 20 };
delete user.age;
console.log(user); // {firstName: "John", lastName:"Doe"}
@@ -1904,11 +1929,11 @@
Below are the main differences between window and document,
- | Window | Document |
- | ----------------------------------------------------------------------------- | --------------------------------------------------------------------------------------------- |
+ | Window | Document |
+ | ----------------------------------------------------------------------------- | ---------------------------------------------------------------------------------------------- |
| It is the root level element in any web page | It is the direct child of the window object. This is also known as Document Object Model (DOM) |
- | By default window object is available implicitly in the page | You can access it via window.document or document. |
- | It has methods like alert(), confirm() and properties like document, location | It provides methods like getElementById, getElementsByTagName, createElement etc |
+ | By default window object is available implicitly in the page | You can access it via window.document or document. |
+ | It has methods like alert(), confirm() and properties like document, location | It provides methods like getElementById, getElementsByTagName, createElement etc |
**[⬆ Back to Top](#table-of-contents)**
@@ -1976,15 +2001,19 @@
| If you try to read the value of an undeclared variable, then a runtime error is encountered | If you try to read the value of an undefined variable, an undefined value is returned. |
```javascript
+
var a;
a; // yields undefined
b; // Throws runtime error like „Uncaught ReferenceError: b is not defined“
+
```
This can be confusing, because it says „not defined“ instead of „not declared“ (Chrome)
**[⬆ Back to Top](#table-of-contents)**
+ ```
+
81. ### What are global variables
Global variables are those that are available throughout the length of the code without any scope. The var keyword is used to declare a local variable but if you omit it then it will become global variable
@@ -2131,8 +2160,8 @@
91. ### What is the difference between native, host and user objects
`Native objects` are objects that are part of the JavaScript language defined by the ECMAScript specification. For example, String, Math, RegExp, Object, Function etc core objects defined in the ECMAScript spec.
- `Host objects` are objects provided by the browser or runtime environment (Node).
-
+ `Host objects` are objects provided by the browser or runtime environment (Node).
+
For example, window, XmlHttpRequest, DOM nodes etc are considered as host objects.
`User objects` are objects defined in the javascript code. For example, User objects created for profile information.
@@ -2161,8 +2190,8 @@
**Cons:**
- 1. It makes little complex code
- 2. You need to load a polyfill if ES6 is not supported
+ 5. It makes little complex code
+ 6. You need to load a polyfill if ES6 is not supported
**[⬆ Back to Top](#table-of-contents)**
@@ -2228,1554 +2257,1556 @@
**[⬆ Back to Top](#table-of-contents)**
-100. ### What are events
-
- Events are "things" that happen to HTML elements. When JavaScript is used in HTML pages, JavaScript can `react` on these events. Some of the examples of HTML events are,
+100. ### What are events
- 1. Web page has finished loading
- 2. Input field was changed
- 3. Button was clicked
+ Events are "things" that happen to HTML elements. When JavaScript is used in HTML pages, JavaScript can `react` on these events. Some of the examples of HTML events are,
- Let's describe the behavior of click event for button element,
+ 1. Web page has finished loading
+ 2. Input field was changed
+ 3. Button was clicked
- ```javascript
-
-
-
-
-
-
-
-
-
- ```
+ Let's describe the behavior of click event for button element,
- **[⬆ Back to Top](#table-of-contents)**
+ ```javascript
+
+
+
+
+
+
+
+
+
+ ```
-101. ### Who created javascript
+ **[⬆ Back to Top](#table-of-contents)**
- JavaScript was created by Brendan Eich in 1995 during his time at Netscape Communications. Initially it was developed under the name `Mocha`, but later the language was officially called `LiveScript` when it first shipped in beta releases of Netscape.
+101. ### Who created javascript
- **[⬆ Back to Top](#table-of-contents)**
+ JavaScript was created by Brendan Eich in 1995 during his time at Netscape Communications. Initially it was developed under the name `Mocha`, but later the language was officially called `LiveScript` when it first shipped in beta releases of Netscape.
-102. ### What is the use of preventDefault method
+ **[⬆ Back to Top](#table-of-contents)**
- The preventDefault() method cancels the event if it is cancelable, meaning that the default action or behaviour that belongs to the event will not occur. For example, prevent form submission when clicking on submit button and prevent opening the page URL when clicking on hyperlink are some common use cases.
+102. ### What is the use of preventDefault method
- ```javascript
- document
- .getElementById("link")
- .addEventListener("click", function (event) {
- event.preventDefault();
- });
- ```
+ The preventDefault() method cancels the event if it is cancelable, meaning that the default action or behaviour that belongs to the event will not occur. For example, prevent form submission when clicking on submit button and prevent opening the page URL when clicking on hyperlink are some common use cases.
- **Note:** Remember that not all events are cancelable.
+ ```javascript
+ document
+ .getElementById("link")
+ .addEventListener("click", function (event) {
+ event.preventDefault();
+ });
+ ```
- **[⬆ Back to Top](#table-of-contents)**
+ **Note:** Remember that not all events are cancelable.
-103. ### What is the use of stopPropagation method
+ **[⬆ Back to Top](#table-of-contents)**
- The stopPropagation method is used to stop the event from bubbling up the event chain. For example, the below nested divs with stopPropagation method prevents default event propagation when clicking on nested div(Div1)
+103. ### What is the use of stopPropagation method
- ```javascript
-
Click DIV1 Element
-
DIV 2
-
DIV 1
-
+ The stopPropagation method is used to stop the event from bubbling up the event chain. For example, the below nested divs with stopPropagation method prevents default event propagation when clicking on nested div(Div1)
-
- ```
+
+ ```
-104. ### What are the steps involved in return false usage
+ **[⬆ Back to Top](#table-of-contents)**
- The return false statement in event handlers performs the below steps,
+104. ### What are the steps involved in return false usage
- 1. First it stops the browser's default action or behaviour.
- 2. It prevents the event from propagating the DOM
- 3. Stops callback execution and returns immediately when called.
+ The return false statement in event handlers performs the below steps,
- **[⬆ Back to Top](#table-of-contents)**
+ 1. First it stops the browser's default action or behaviour.
+ 2. It prevents the event from propagating the DOM
+ 3. Stops callback execution and returns immediately when called.
-105. ### What is BOM
+ **[⬆ Back to Top](#table-of-contents)**
- The Browser Object Model (BOM) allows JavaScript to "talk to" the browser. It consists of the objects navigator, history, screen, location and document which are children of the window. The Browser Object Model is not standardized and can change based on different browsers.
+105. ### What is BOM
- 
+ The Browser Object Model (BOM) allows JavaScript to "talk to" the browser. It consists of the objects navigator, history, screen, location and document which are children of the window. The Browser Object Model is not standardized and can change based on different browsers.
- **[⬆ Back to Top](#table-of-contents)**
+ 
-106. ### What is the use of setTimeout
+ **[⬆ Back to Top](#table-of-contents)**
- The setTimeout() method is used to call a function or evaluate an expression after a specified number of milliseconds. For example, let's log a message after 2 seconds using setTimeout method,
+106. ### What is the use of setTimeout
- ```javascript
- setTimeout(function () {
- console.log("Good morning");
- }, 2000);
- ```
+ The setTimeout() method is used to call a function or evaluate an expression after a specified number of milliseconds. For example, let's log a message after 2 seconds using setTimeout method,
- **[⬆ Back to Top](#table-of-contents)**
+ ```javascript
+ setTimeout(function () {
+ console.log("Good morning");
+ }, 2000);
+ ```
-107. ### What is the use of setInterval
+ **[⬆ Back to Top](#table-of-contents)**
- The setInterval() method is used to call a function or evaluate an expression at specified intervals (in milliseconds). For example, let's log a message after 2 seconds using setInterval method,
+107. ### What is the use of setInterval
- ```javascript
- setInterval(function () {
- console.log("Good morning");
- }, 2000);
- ```
+ The setInterval() method is used to call a function or evaluate an expression at specified intervals (in milliseconds). For example, let's log a message after 2 seconds using setInterval method,
- **[⬆ Back to Top](#table-of-contents)**
+ ```javascript
+ setInterval(function () {
+ console.log("Good morning");
+ }, 2000);
+ ```
-108. ### Why is JavaScript treated as Single threaded
+ **[⬆ Back to Top](#table-of-contents)**
- JavaScript is a single-threaded language. Because the language specification does not allow the programmer to write code so that the interpreter can run parts of it in parallel in multiple threads or processes. Whereas languages like java, go, C++ can make multi-threaded and multi-process programs.
+108. ### Why is JavaScript treated as Single threaded
- **[⬆ Back to Top](#table-of-contents)**
+ JavaScript is a single-threaded language. Because the language specification does not allow the programmer to write code so that the interpreter can run parts of it in parallel in multiple threads or processes. Whereas languages like java, go, C++ can make multi-threaded and multi-process programs.
-109. ### What is an event delegation
+ **[⬆ Back to Top](#table-of-contents)**
- Event delegation is a technique for listening to events where you delegate a parent element as the listener for all of the events that happen inside it.
+109. ### What is an event delegation
- For example, if you wanted to detect field changes inside a specific form, you can use event delegation technique,
+ Event delegation is a technique for listening to events where you delegate a parent element as the listener for all of the events that happen inside it.
- ```javascript
- var form = document.querySelector("#registration-form");
-
- // Listen for changes to fields inside the form
- form.addEventListener(
- "input",
- function (event) {
- // Log the field that was changed
- console.log(event.target);
- },
- false
- );
- ```
+ For example, if you wanted to detect field changes inside a specific form, you can use event delegation technique,
- **[⬆ Back to Top](#table-of-contents)**
+ ```javascript
+ var form = document.querySelector("#registration-form");
+
+ // Listen for changes to fields inside the form
+ form.addEventListener(
+ "input",
+ function (event) {
+ // Log the field that was changed
+ console.log(event.target);
+ },
+ false
+ );
+ ```
-110. ### What is ECMAScript
+ **[⬆ Back to Top](#table-of-contents)**
- ECMAScript is the scripting language that forms the basis of JavaScript. ECMAScript standardized by the ECMA International standards organization in the ECMA-262 and ECMA-402 specifications. The first edition of ECMAScript was released in 1997.
+110. ### What is ECMAScript
- **[⬆ Back to Top](#table-of-contents)**
+ ECMAScript is the scripting language that forms the basis of JavaScript. ECMAScript standardized by the ECMA International standards organization in the ECMA-262 and ECMA-402 specifications. The first edition of ECMAScript was released in 1997.
-111. ### What is JSON
+ **[⬆ Back to Top](#table-of-contents)**
- JSON (JavaScript Object Notation) is a lightweight format that is used for data interchanging. It is based on a subset of JavaScript language in the way objects are built in JavaScript.
+111. ### What is JSON
- **[⬆ Back to Top](#table-of-contents)**
+ JSON (JavaScript Object Notation) is a lightweight format that is used for data interchanging. It is based on a subset of JavaScript language in the way objects are built in JavaScript.
-112. ### What are the syntax rules of JSON
+ **[⬆ Back to Top](#table-of-contents)**
- Below are the list of syntax rules of JSON
+112. ### What are the syntax rules of JSON
- 1. The data is in name/value pairs
- 2. The data is separated by commas
- 3. Curly braces hold objects
- 4. Square brackets hold arrays
+ Below are the list of syntax rules of JSON
- **[⬆ Back to Top](#table-of-contents)**
+ 1. The data is in name/value pairs
+ 2. The data is separated by commas
+ 3. Curly braces hold objects
+ 4. Square brackets hold arrays
-113. ### What is the purpose JSON stringify
+ **[⬆ Back to Top](#table-of-contents)**
- When sending data to a web server, the data has to be in a string format. You can achieve this by converting JSON object into a string using stringify() method.
+113. ### What is the purpose JSON stringify
- ```javascript
- var userJSON = { name: "John", age: 31 };
- var userString = JSON.stringify(userJSON);
- console.log(userString); //"{"name":"John","age":31}"
- ```
+ When sending data to a web server, the data has to be in a string format. You can achieve this by converting JSON object into a string using stringify() method.
- **[⬆ Back to Top](#table-of-contents)**
+ ```javascript
+ var userJSON = { name: "John", age: 31 };
+ var userString = JSON.stringify(userJSON);
+ console.log(userString); //"{"name":"John","age":31}"
+ ```
-114. ### How do you parse JSON string
+ **[⬆ Back to Top](#table-of-contents)**
- When receiving the data from a web server, the data is always in a string format. But you can convert this string value to a javascript object using parse() method.
+114. ### How do you parse JSON string
- ```javascript
- var userString = '{"name":"John","age":31}';
- var userJSON = JSON.parse(userString);
- console.log(userJSON); // {name: "John", age: 31}
- ```
+ When receiving the data from a web server, the data is always in a string format. But you can convert this string value to a javascript object using parse() method.
- **[⬆ Back to Top](#table-of-contents)**
+ ```javascript
+ var userString = '{"name":"John","age":31}';
+ var userJSON = JSON.parse(userString);
+ console.log(userJSON); // {name: "John", age: 31}
+ ```
-115. ### Why do you need JSON
+ **[⬆ Back to Top](#table-of-contents)**
- When exchanging data between a browser and a server, the data can only be text. Since JSON is text only, it can easily be sent to and from a server, and used as a data format by any programming language.
+115. ### Why do you need JSON
- **[⬆ Back to Top](#table-of-contents)**
+ When exchanging data between a browser and a server, the data can only be text. Since JSON is text only, it can easily be sent to and from a server, and used as a data format by any programming language.
-116. ### What are PWAs
+ **[⬆ Back to Top](#table-of-contents)**
- Progressive web applications (PWAs) are a type of mobile app delivered through the web, built using common web technologies including HTML, CSS and JavaScript. These PWAs are deployed to servers, accessible through URLs, and indexed by search engines.
+116. ### What are PWAs
- **[⬆ Back to Top](#table-of-contents)**
+ Progressive web applications (PWAs) are a type of mobile app delivered through the web, built using common web technologies including HTML, CSS and JavaScript. These PWAs are deployed to servers, accessible through URLs, and indexed by search engines.
-117. ### What is the purpose of clearTimeout method
+ **[⬆ Back to Top](#table-of-contents)**
- The clearTimeout() function is used in javascript to clear the timeout which has been set by setTimeout()function before that. i.e, The return value of setTimeout() function is stored in a variable and it’s passed into the clearTimeout() function to clear the timer.
+117. ### What is the purpose of clearTimeout method
- For example, the below setTimeout method is used to display the message after 3 seconds. This timeout can be cleared by the clearTimeout() method.
+ The clearTimeout() function is used in javascript to clear the timeout which has been set by setTimeout()function before that. i.e, The return value of setTimeout() function is stored in a variable and it’s passed into the clearTimeout() function to clear the timer.
- ```javascript
-
- ```
+ }
- **[⬆ Back to Top](#table-of-contents)**
+ function stop() {
+ clearTimeout(msg);
+ }
+
+ ```
-118. ### What is the purpose of clearInterval method
+ **[⬆ Back to Top](#table-of-contents)**
- The clearInterval() function is used in javascript to clear the interval which has been set by setInterval() function. i.e, The return value returned by setInterval() function is stored in a variable and it’s passed into the clearInterval() function to clear the interval.
+118. ### What is the purpose of clearInterval method
- For example, the below setInterval method is used to display the message for every 3 seconds. This interval can be cleared by the clearInterval() method.
+ The clearInterval() function is used in javascript to clear the interval which has been set by setInterval() function. i.e, The return value returned by setInterval() function is stored in a variable and it’s passed into the clearInterval() function to clear the interval.
- ```javascript
-
- ```
+ }
- **[⬆ Back to Top](#table-of-contents)**
+ function stop() {
+ clearInterval(msg);
+ }
+
+ ```
-119. ### How do you redirect new page in javascript
+ **[⬆ Back to Top](#table-of-contents)**
- In vanilla javascript, you can redirect to a new page using the `location` property of window object. The syntax would be as follows,
+119. ### How do you redirect new page in javascript
- ```javascript
- function redirect() {
- window.location.href = "newPage.html";
- }
- ```
+ In vanilla javascript, you can redirect to a new page using the `location` property of window object. The syntax would be as follows,
- **[⬆ Back to Top](#table-of-contents)**
+ ```javascript
+ function redirect() {
+ window.location.href = "newPage.html";
+ }
+ ```
-120. ### How do you check whether a string contains a substring
+ **[⬆ Back to Top](#table-of-contents)**
- There are 3 possible ways to check whether a string contains a substring or not,
+120. ### How do you check whether a string contains a substring
- 1. **Using includes:** ES6 provided `String.prototype.includes` method to test a string contains a substring
+ There are 3 possible ways to check whether a string contains a substring or not,
- ```javascript
- var mainString = "hello",
- subString = "hell";
- mainString.includes(subString);
- ```
+ 1. **Using includes:** ES6 provided `String.prototype.includes` method to test a string contains a substring
- 2. **Using indexOf:** In an ES5 or older environment, you can use `String.prototype.indexOf` which returns the index of a substring. If the index value is not equal to -1 then it means the substring exists in the main string.
+ ```javascript
+ var mainString = "hello",
+ subString = "hell";
+ mainString.includes(subString);
+ ```
- ```javascript
- var mainString = "hello",
- subString = "hell";
- mainString.indexOf(subString) !== -1;
- ```
+ 2. **Using indexOf:** In an ES5 or older environment, you can use `String.prototype.indexOf` which returns the index of a substring. If the index value is not equal to -1 then it means the substring exists in the main string.
- 3. **Using RegEx:** The advanced solution is using Regular expression's test method(`RegExp.test`), which allows for testing for against regular expressions
+ ```javascript
+ var mainString = "hello",
+ subString = "hell";
+ mainString.indexOf(subString) !== -1;
+ ```
- ```javascript
- var mainString = "hello",
- regex = /hell/;
- regex.test(mainString);
- ```
+ 3. **Using RegEx:** The advanced solution is using Regular expression's test method(`RegExp.test`), which allows for testing for against regular expressions
- **[⬆ Back to Top](#table-of-contents)**
+ ```javascript
+ var mainString = "hello",
+ regex = /hell/;
+ regex.test(mainString);
+ ```
-121. ### How do you validate an email in javascript
+ **[⬆ Back to Top](#table-of-contents)**
- You can validate an email in javascript using regular expressions. It is recommended to do validations on the server side instead of the client side. Because the javascript can be disabled on the client side.
+121. ### How do you validate an email in javascript
- ```javascript
- function validateEmail(email) {
- var re =
- /^(([^<>()\[\]\\.,;:\s@"]+(\.[^<>()\[\]\\.,;:\s@"]+)*)|(".+"))@((\[[0-9]{1,3}\.[0-9]{1,3}\.[0-9]{1,3}\.[0-9]{1,3}\])|(([a-zA-Z\-0-9]+\.)+[a-zA-Z]{2,}))$/;
- return re.test(String(email).toLowerCase());
- }
- ```
+ You can validate an email in javascript using regular expressions. It is recommended to do validations on the server side instead of the client side. Because the javascript can be disabled on the client side.
- **[⬆ Back to Top](#table-of-contents)**
+ ```javascript
+ function validateEmail(email) {
+ var re =
+ /^(([^<>()\[\]\\.,;:\s@"]+(\.[^<>()\[\]\\.,;:\s@"]+)*)|(".+"))@((\[[0-9]{1,3}\.[0-9]{1,3}\.[0-9]{1,3}\.[0-9]{1,3}\])|(([a-zA-Z\-0-9]+\.)+[a-zA-Z]{2,}))$/;
+ return re.test(String(email).toLowerCase());
+ }
+ ```
- The above regular expression accepts unicode characters.
+ **[⬆ Back to Top](#table-of-contents)**
-122. ### How do you get the current url with javascript
+ The above regular expression accepts unicode characters.
- You can use `window.location.href` expression to get the current url path and you can use the same expression for updating the URL too. You can also use `document.URL` for read-only purposes but this solution has issues in FF.
+122. ### How do you get the current url with javascript
- ```javascript
- console.log("location.href", window.location.href); // Returns full URL
- ```
+ You can use `window.location.href` expression to get the current url path and you can use the same expression for updating the URL too. You can also use `document.URL` for read-only purposes but this solution has issues in FF.
- **[⬆ Back to Top](#table-of-contents)**
+ ```javascript
+ console.log("location.href", window.location.href); // Returns full URL
+ ```
-123. ### What are the various url properties of location object
+ **[⬆ Back to Top](#table-of-contents)**
- The below `Location` object properties can be used to access URL components of the page,
+123. ### What are the various url properties of location object
- 1. href - The entire URL
- 2. protocol - The protocol of the URL
- 3. host - The hostname and port of the URL
- 4. hostname - The hostname of the URL
- 5. port - The port number in the URL
- 6. pathname - The path name of the URL
- 7. search - The query portion of the URL
- 8. hash - The anchor portion of the URL
+ The below `Location` object properties can be used to access URL components of the page,
- **[⬆ Back to Top](#table-of-contents)**
+ 1. href - The entire URL
+ 2. protocol - The protocol of the URL
+ 3. host - The hostname and port of the URL
+ 4. hostname - The hostname of the URL
+ 5. port - The port number in the URL
+ 6. pathname - The path name of the URL
+ 7. search - The query portion of the URL
+ 8. hash - The anchor portion of the URL
-124. ### How do get query string values in javascript
+ **[⬆ Back to Top](#table-of-contents)**
- You can use URLSearchParams to get query string values in javascript. Let's see an example to get the client code value from URL query string,
+124. ### How do get query string values in javascript
- ```javascript
- const urlParams = new URLSearchParams(window.location.search);
- const clientCode = urlParams.get("clientCode");
- ```
+ You can use URLSearchParams to get query string values in javascript. Let's see an example to get the client code value from URL query string,
- **[⬆ Back to Top](#table-of-contents)**
+ ```javascript
+ const urlParams = new URLSearchParams(window.location.search);
+ const clientCode = urlParams.get("clientCode");
+ ```
-125. ### How do you check if a key exists in an object
+ **[⬆ Back to Top](#table-of-contents)**
- You can check whether a key exists in an object or not using three approaches,
+125. ### How do you check if a key exists in an object
- 1. **Using in operator:** You can use the in operator whether a key exists in an object or not
+ You can check whether a key exists in an object or not using three approaches,
- ```javascript
- "key" in obj;
- ```
+ 1. **Using in operator:** You can use the in operator whether a key exists in an object or not
- and If you want to check if a key doesn't exist, remember to use parenthesis,
+ ```javascript
+ "key" in obj;
+ ```
- ```javascript
- !("key" in obj);
- ```
+ and If you want to check if a key doesn't exist, remember to use parenthesis,
- 2. **Using hasOwnProperty method:** You can use `hasOwnProperty` to particularly test for properties of the object instance (and not inherited properties)
+ ```javascript
+ !("key" in obj);
+ ```
- ```javascript
- obj.hasOwnProperty("key"); // true
- ```
+ 2. **Using hasOwnProperty method:** You can use `hasOwnProperty` to particularly test for properties of the object instance (and not inherited properties)
- 3. **Using undefined comparison:** If you access a non-existing property from an object, the result is undefined. Let’s compare the properties against undefined to determine the existence of the property.
+ ```javascript
+ obj.hasOwnProperty("key"); // true
+ ```
- ```javascript
- const user = {
- name: "John",
- };
+ 3. **Using undefined comparison:** If you access a non-existing property from an object, the result is undefined. Let’s compare the properties against undefined to determine the existence of the property.
- console.log(user.name !== undefined); // true
- console.log(user.nickName !== undefined); // false
- ```
+ ```javascript
+ const user = {
+ name: "John",
+ };
- **[⬆ Back to Top](#table-of-contents)**
+ console.log(user.name !== undefined); // true
+ console.log(user.nickName !== undefined); // false
+ ```
-126. ### How do you loop through or enumerate javascript object
+ **[⬆ Back to Top](#table-of-contents)**
- You can use the `for-in` loop to loop through javascript object. You can also make sure that the key you get is an actual property of an object, and doesn't come from the prototype using `hasOwnProperty` method.
+126. ### How do you loop through or enumerate javascript object
- ```javascript
- var object = {
- k1: "value1",
- k2: "value2",
- k3: "value3",
- };
+ You can use the `for-in` loop to loop through javascript object. You can also make sure that the key you get is an actual property of an object, and doesn't come from the prototype using `hasOwnProperty` method.
- for (var key in object) {
- if (object.hasOwnProperty(key)) {
- console.log(key + " -> " + object[key]); // k1 -> value1 ...
- }
- }
- ```
+ ```javascript
+ var object = {
+ k1: "value1",
+ k2: "value2",
+ k3: "value3",
+ };
- **[⬆ Back to Top](#table-of-contents)**
+ for (var key in object) {
+ if (object.hasOwnProperty(key)) {
+ console.log(key + " -> " + object[key]); // k1 -> value1 ...
+ }
+ }
+ ```
-127. ### How do you test for an empty object
+ **[⬆ Back to Top](#table-of-contents)**
- There are different solutions based on ECMAScript versions
+127. ### How do you test for an empty object
- 1. **Using Object entries(ECMA 7+):** You can use object entries length along with constructor type.
+ There are different solutions based on ECMAScript versions
- ```javascript
- Object.entries(obj).length === 0 && obj.constructor === Object; // Since date object length is 0, you need to check constructor check as well
- ```
+ 1. **Using Object entries(ECMA 7+):** You can use object entries length along with constructor type.
- 2. **Using Object keys(ECMA 5+):** You can use object keys length along with constructor type.
+ ```javascript
+ Object.entries(obj).length === 0 && obj.constructor === Object; // Since date object length is 0, you need to check constructor check as well
+ ```
- ```javascript
- Object.keys(obj).length === 0 && obj.constructor === Object; // Since date object length is 0, you need to check constructor check as well
- ```
+ 2. **Using Object keys(ECMA 5+):** You can use object keys length along with constructor type.
- 3. **Using for-in with hasOwnProperty(Pre-ECMA 5):** You can use a for-in loop along with hasOwnProperty.
+ ```javascript
+ Object.keys(obj).length === 0 && obj.constructor === Object; // Since date object length is 0, you need to check constructor check as well
+ ```
- ```javascript
- function isEmpty(obj) {
- for (var prop in obj) {
- if (obj.hasOwnProperty(prop)) {
- return false;
- }
- }
+ 3. **Using for-in with hasOwnProperty(Pre-ECMA 5):** You can use a for-in loop along with hasOwnProperty.
- return JSON.stringify(obj) === JSON.stringify({});
- }
- ```
+ ```javascript
+ function isEmpty(obj) {
+ for (var prop in obj) {
+ if (obj.hasOwnProperty(prop)) {
+ return false;
+ }
+ }
- **[⬆ Back to Top](#table-of-contents)**
+ return JSON.stringify(obj) === JSON.stringify({});
+ }
+ ```
-128. ### What is an arguments object
+ **[⬆ Back to Top](#table-of-contents)**
- The arguments object is an Array-like object accessible inside functions that contains the values of the arguments passed to that function. For example, let's see how to use arguments object inside sum function,
+128. ### What is an arguments object
- ```javascript
- function sum() {
- var total = 0;
- for (var i = 0, len = arguments.length; i < len; ++i) {
- total += arguments[i];
- }
- return total;
- }
+ The arguments object is an Array-like object accessible inside functions that contains the values of the arguments passed to that function. For example, let's see how to use arguments object inside sum function,
- sum(1, 2, 3); // returns 6
- ```
+ ```javascript
+ function sum() {
+ var total = 0;
+ for (var i = 0, len = arguments.length; i < len; ++i) {
+ total += arguments[i];
+ }
+ return total;
+ }
- **Note:** You can't apply array methods on arguments object. But you can convert into a regular array as below.
+ sum(1, 2, 3); // returns 6
+ ```
- ```javascript
- var argsArray = Array.prototype.slice.call(arguments);
- ```
+ **Note:** You can't apply array methods on arguments object. But you can convert into a regular array as below.
- **[⬆ Back to Top](#table-of-contents)**
+ ```javascript
+ var argsArray = Array.prototype.slice.call(arguments);
+ ```
-129. ### How do you make first letter of the string in an uppercase
+ **[⬆ Back to Top](#table-of-contents)**
- You can create a function which uses a chain of string methods such as charAt, toUpperCase and slice methods to generate a string with the first letter in uppercase.
+129. ### How do you make first letter of the string in an uppercase
- ```javascript
- function capitalizeFirstLetter(string) {
- return string.charAt(0).toUpperCase() + string.slice(1);
- }
- ```
+ You can create a function which uses a chain of string methods such as charAt, toUpperCase and slice methods to generate a string with the first letter in uppercase.
- **[⬆ Back to Top](#table-of-contents)**
+ ```javascript
+ function capitalizeFirstLetter(string) {
+ return string.charAt(0).toUpperCase() + string.slice(1);
+ }
+ ```
-130. ### What are the pros and cons of for loops
+ **[⬆ Back to Top](#table-of-contents)**
- The for-loop is a commonly used iteration syntax in javascript. It has both pros and cons
+130. ### What are the pros and cons of for loops
- #### Pros
+ The for-loop is a commonly used iteration syntax in javascript. It has both pros and cons
- 1. Works on every environment
- 2. You can use break and continue flow control statements
+ #### Pros
- #### Cons
+ 1. Works on every environment
+ 2. You can use break and continue flow control statements
- 3. Too verbose
- 4. Imperative
- 5. You might face off-by-one errors.
+ #### Cons
- **[⬆ Back to Top](#table-of-contents)**
+ 3. Too verbose
+ 4. Imperative
+ 5. You might face off-by-one errors.
-131. ### How do you display the current date in javascript
+ **[⬆ Back to Top](#table-of-contents)**
- You can use `new Date()` to generate a new Date object containing the current date and time. For example, let's display the current date in mm/dd/yyyy
+131. ### How do you display the current date in javascript
- ```javascript
- var today = new Date();
- var dd = String(today.getDate()).padStart(2, "0");
- var mm = String(today.getMonth() + 1).padStart(2, "0"); //January is 0!
- var yyyy = today.getFullYear();
+ You can use `new Date()` to generate a new Date object containing the current date and time. For example, let's display the current date in mm/dd/yyyy
- today = mm + "/" + dd + "/" + yyyy;
- document.write(today);
- ```
+ ```javascript
+ var today = new Date();
+ var dd = String(today.getDate()).padStart(2, "0");
+ var mm = String(today.getMonth() + 1).padStart(2, "0"); //January is 0!
+ var yyyy = today.getFullYear();
- **[⬆ Back to Top](#table-of-contents)**
+ today = mm + "/" + dd + "/" + yyyy;
+ document.write(today);
+ ```
-132. ### How do you compare two date objects
+ **[⬆ Back to Top](#table-of-contents)**
- You need to use date.getTime() method in order to compare unix timestamp values
+132. ### How do you compare two date objects
- ```javascript
- var d1 = new Date();
- var d2 = new Date(d1);
- console.log(d1.getTime() === d2.getTime()); //True
- console.log(d1 === d2); // False
- ```
+ You need to use date.getTime() method in order to compare unix timestamp values
- **[⬆ Back to Top](#table-of-contents)**
+ ```javascript
+ var d1 = new Date();
+ var d2 = new Date(d1);
+ console.log(d1.getTime() === d2.getTime()); //True
+ console.log(d1 === d2); // False
+ ```
-133. ### How do you check if a string starts with another string
+ **[⬆ Back to Top](#table-of-contents)**
- You can use ECMAScript 6's `String.prototype.startsWith()` method to check if a string starts with another string or not. But it is not yet supported in all browsers. Let's see an example to see this usage,
+133. ### How do you check if a string starts with another string
- ```javascript
- "Good morning".startsWith("Good"); // true
- "Good morning".startsWith("morning"); // false
- ```
+ You can use ECMAScript 6's `String.prototype.startsWith()` method to check if a string starts with another string or not. But it is not yet supported in all browsers. Let's see an example to see this usage,
- **[⬆ Back to Top](#table-of-contents)**
+ ```javascript
+ "Good morning".startsWith("Good"); // true
+ "Good morning".startsWith("morning"); // false
+ ```
-134. ### How do you trim a string in javascript
+ **[⬆ Back to Top](#table-of-contents)**
- JavaScript provided a trim method on string types to trim any whitespaces present at the beginning or ending of the string.
+134. ### How do you trim a string in javascript
- ```javascript
- " Hello World ".trim(); //Hello World
- ```
+ JavaScript provided a trim method on string types to trim any whitespaces present at the beginning or ending of the string.
- If your browser(";
- }
- ```
+ **[⬆ Back to Top](#table-of-contents)**
- The continue statement is used to "jump over" one iteration in the loop. i.e, It breaks one iteration (in the loop), if a specified condition occurs, and continues with the next iteration in the loop.
+143. ### What are break and continue statements
- ```javascript
- for (i = 0; i < 10; i++) {
- if (i === 5) {
- continue;
- }
- text += "Number: " + i + " ";
- }
- ```
+ The break statement is used to "jump out" of a loop. i.e, It breaks the loop and continues executing the code after the loop.
- **[⬆ Back to Top](#table-of-contents)**
+ ```javascript
+ for (i = 0; i < 10; i++) {
+ if (i === 5) {
+ break;
+ }
+ text += "Number: " + i + " ";
+ }
+ ```
-144. ### What are js labels
+ The continue statement is used to "jump over" one iteration in the loop. i.e, It breaks one iteration (in the loop), if a specified condition occurs, and continues with the next iteration in the loop.
- The label statement allows us to name loops and blocks in JavaScript. We can then use these labels to refer back to the code later. For example, the below code with labels avoids printing the numbers when they are same,
+ ```javascript
+ for (i = 0; i < 10; i++) {
+ if (i === 5) {
+ continue;
+ }
+ text += "Number: " + i + " ";
+ }
+ ```
- ```javascript
- var i, j;
+ **[⬆ Back to Top](#table-of-contents)**
- loop1: for (i = 0; i < 3; i++) {
- loop2: for (j = 0; j < 3; j++) {
- if (i === j) {
- continue loop1;
- }
- console.log("i = " + i + ", j = " + j);
- }
- }
+144. ### What are js labels
- // Output is:
- // "i = 1, j = 0"
- // "i = 2, j = 0"
- // "i = 2, j = 1"
- ```
+ The label statement allows us to name loops and blocks in JavaScript. We can then use these labels to refer back to the code later. For example, the below code with labels avoids printing the numbers when they are same,
- **[⬆ Back to Top](#table-of-contents)**
+ ```javascript
+ var i, j;
-145. ### What are the benefits of keeping declarations at the top
+ loop1: for (i = 0; i < 3; i++) {
+ loop2: for (j = 0; j < 3; j++) {
+ if (i === j) {
+ continue loop1;
+ }
+ console.log("i = " + i + ", j = " + j);
+ }
+ }
- It is recommended to keep all declarations at the top of each script or function. The benefits of doing this are,
+ // Output is:
+ // "i = 1, j = 0"
+ // "i = 2, j = 0"
+ // "i = 2, j = 1"
+ ```
- 1. Gives cleaner code
- 2. It provides a single place to look for local variables
- 3. Easy to avoid unwanted global variables
- 4. It reduces the possibility of unwanted re-declarations
+ **[⬆ Back to Top](#table-of-contents)**
- **[⬆ Back to Top](#table-of-contents)**
+145. ### What are the benefits of keeping declarations at the top
-146. ### What are the benefits of initializing variables
+ It is recommended to keep all declarations at the top of each script or function. The benefits of doing this are,
- It is recommended to initialize variables because of the below benefits,
+ 1. Gives cleaner code
+ 2. It provides a single place to look for local variables
+ 3. Easy to avoid unwanted global variables
+ 4. It reduces the possibility of unwanted re-declarations
- 1. It gives cleaner code
- 2. It provides a single place to initialize variables
- 3. Avoid undefined values in the code
+ **[⬆ Back to Top](#table-of-contents)**
- **[⬆ Back to Top](#table-of-contents)**
+146. ### What are the benefits of initializing variables
-147. ### What are the recommendations to create new object
+ It is recommended to initialize variables because of the below benefits,
- It is recommended to avoid creating new objects using `new Object()`. Instead you can initialize values based on it's type to create the objects.
+ 1. It gives cleaner code
+ 2. It provides a single place to initialize variables
+ 3. Avoid undefined values in the code
- 1. Assign {} instead of new Object()
- 2. Assign "" instead of new String()
- 3. Assign 0 instead of new Number()
- 4. Assign false instead of new Boolean()
- 5. Assign [] instead of new Array()
- 6. Assign /()/ instead of new RegExp()
- 7. Assign function (){} instead of new Function()
+ **[⬆ Back to Top](#table-of-contents)**
- You can define them as an example,
+147. ### What are the recommendations to create new object
- ```javascript
- var v1 = {};
- var v2 = "";
- var v3 = 0;
- var v4 = false;
- var v5 = [];
- var v6 = /()/;
- var v7 = function () {};
- ```
+ It is recommended to avoid creating new objects using `new Object()`. Instead you can initialize values based on it's type to create the objects.
- **[⬆ Back to Top](#table-of-contents)**
+ 1. Assign {} instead of new Object()
+ 2. Assign "" instead of new String()
+ 3. Assign 0 instead of new Number()
+ 4. Assign false instead of new Boolean()
+ 5. Assign [] instead of new Array()
+ 6. Assign /()/ instead of new RegExp()
+ 7. Assign function (){} instead of new Function()
-148. ### How do you define JSON arrays
+ You can define them as an example,
- JSON arrays are written inside square brackets and arrays contain javascript objects. For example, the JSON array of users would be as below,
+ ```javascript
+ var v1 = {};
+ var v2 = "";
+ var v3 = 0;
+ var v4 = false;
+ var v5 = [];
+ var v6 = /()/;
+ var v7 = function () {};
+ ```
- ```javascript
- "users":[
- {"firstName":"John", "lastName":"Abrahm"},
- {"firstName":"Anna", "lastName":"Smith"},
- {"firstName":"Shane", "lastName":"Warn"}
- ]
- ```
+ **[⬆ Back to Top](#table-of-contents)**
- **[⬆ Back to Top](#table-of-contents)**
+148. ### How do you define JSON arrays
-149. ### How do you generate random integers
+ JSON arrays are written inside square brackets and arrays contain javascript objects. For example, the JSON array of users would be as below,
- You can use Math.random() with Math.floor() to return random integers. For example, if you want generate random integers between 1 to 10, the multiplication factor should be 10,
+ ```javascript
+ "users":[
+ {"firstName":"John", "lastName":"Abrahm"},
+ {"firstName":"Anna", "lastName":"Smith"},
+ {"firstName":"Shane", "lastName":"Warn"}
+ ]
+ ```
- ```javascript
- Math.floor(Math.random() * 10) + 1; // returns a random integer from 1 to 10
- Math.floor(Math.random() * 100) + 1; // returns a random integer from 1 to 100
- ```
+ **[⬆ Back to Top](#table-of-contents)**
- **Note:** Math.random() returns a random number between 0 (inclusive), and 1 (exclusive)
+149. ### How do you generate random integers
- **[⬆ Back to Top](#table-of-contents)**
+ You can use `Math.random()` with `Math.floor()` to return random integers. For example, if you want generate random integers between 1 to 10, the multiplication factor should be 10,
-150. ### Can you write a random integers function to print integers within a range
+ ```javascript
+ Math.floor(Math.random() * 10) + 1; // returns a random integer from 1 to 10
+ Math.floor(Math.random() * 100) + 1; // returns a random integer from 1 to 100
+ ```
- Yes, you can create a proper random function to return a random number between min and max (both included)
+ **Note:** `Math.random()` returns a random number between 0 (inclusive), and 1 (exclusive)
- ```javascript
- function randomInteger(min, max) {
- return Math.floor(Math.random() * (max - min + 1)) + min;
- }
- randomInteger(1, 100); // returns a random integer from 1 to 100
- randomInteger(1, 1000); // returns a random integer from 1 to 1000
- ```
+ **[⬆ Back to Top](#table-of-contents)**
- **[⬆ Back to Top](#table-of-contents)**
+150. ### Can you write a random integers function to print integers within a range
-151. ### What is tree shaking
+ Yes, you can create a proper random function to return a random number between min and max (both included)
- Tree shaking is a form of dead code elimination. It means that unused modules will not be included in the bundle during the build process and for that it relies on the static structure of ES2015 module syntax,( i.e. import and export). Initially this has been popularized by the ES2015 module bundler `rollup`.
+ ```javascript
+ function randomInteger(min, max) {
+ return Math.floor(Math.random() * (max - min + 1)) + min;
+ }
+ randomInteger(1, 100); // returns a random integer from 1 to 100
+ randomInteger(1, 1000); // returns a random integer from 1 to 1000
+ ```
- **[⬆ Back to Top](#table-of-contents)**
+ **[⬆ Back to Top](#table-of-contents)**
-152. ### What is the need of tree shaking
+151. ### What is tree shaking
- Tree Shaking can significantly reduce the code size in any application. i.e, The less code we send over the wire the more performant the application will be. For example, if we just want to create a “Hello World” Application using SPA frameworks then it will take around a few MBs, but by tree shaking it can bring down the size to just a few hundred KBs. Tree shaking is implemented in Rollup and Webpack bundlers.
+ Tree shaking is a form of dead code elimination. It means that unused modules will not be included in the bundle during the build process and for that it relies on the static structure of ES2015 module syntax,( i.e. import and export). Initially this has been popularized by the ES2015 module bundler `rollup`, these days practically all bundlers use this technique.
- **[⬆ Back to Top](#table-of-contents)**
+ **[⬆ Back to Top](#table-of-contents)**
-153. ### Is it recommended to use eval
+152. ### What is the need of tree shaking
- No, it allows arbitrary code to be run which causes a security problem. As we know that the eval() function is used to run text as code. In most of the cases, it should not be necessary to use it.
+ Tree Shaking can significantly reduce the code size in any application. i.e, The less code we send over the wire the more performant the application will be. For example, if we just want to create a “Hello World” Application using SPA frameworks then it will take around a few MBs, but by tree shaking it can bring down the size to just a few hundred KBs. Tree shaking is implemented in Rollup and Webpack bundlers.
- **[⬆ Back to Top](#table-of-contents)**
+ **[⬆ Back to Top](#table-of-contents)**
-154. ### What is a Regular Expression
+153. ### Is it recommended to use eval
- A regular expression is a sequence of characters that forms a search pattern. You can use this search pattern for searching data in a text. These can be used to perform all types of text search and text replace operations. Let's see the syntax format now,
+ No, it allows arbitrary code to be run which causes a security problem. As we know that the eval() function is used to run text as code. In most of the cases, it should not be necessary to use it.
- ```javascript
- /pattern/modifiers;
- ```
+ **[⬆ Back to Top](#table-of-contents)**
- For example, the regular expression or search pattern with case-insensitive username would be,
+154. ### What is a Regular Expression
- ```javascript
- /John/i;
- ```
+ A regular expression is a sequence of characters that forms a search pattern. You can use this search pattern for searching data in a text. These can be used to perform all types of text search and text replace operations. Let's see the syntax format now,
- **[⬆ Back to Top](#table-of-contents)**
+ ```javascript
+ /pattern/modifiers;
+ ```
-155. ### What are the string methods that accept Regular expression
+ For example, the regular expression or search pattern with case-insensitive username would be,
- There are six string methods: search(), replace(), replaceAll(), match(), matchAll(), and split().
+ ```javascript
+ /John/i;
+ ```
- The search() method uses an expression to search for a match, and returns the position of the match.
+ **[⬆ Back to Top](#table-of-contents)**
- ```javascript
- var msg = "Hello John";
- var n = msg.search(/John/i); // 6
- ```
+155. ### What are the string methods that accept Regular expression
- The replace() and replaceAll() methods are used to return a modified string where the pattern is replaced.
+ There are six string methods: `search()`, `replace()`, `replaceAll()`, `match()`, `matchAll()`, and `split()`.
- ```javascript
- var msg = "ball bat";
- var n1 = msg.replace(/b/i, "c"); // call bat
- var n2 = msg.replaceAll(/b/i, "c"); // call cat
- ```
+ The `search()` method uses an expression to search for a match, and returns the position of the match.
- The match() and matchAll() methods are used to return the matches when matching a string against a regular expression.
+ ```javascript
+ var msg = "Hello John";
+ var n = msg.search(/John/i); // 6
+ ```
- ```javascript
- var msg = "Hello John";
- var n1 = msg.match(/[A-Z]/g); // ["H", "J"]
- var n2 = msg.matchAll(/[A-Z]/g); // this returns an iterator
- ```
+ The `replace()` and `replaceAll()` methods are used to return a modified string where the pattern is replaced.
- The split() method is used to split a string into an array of substrings, and returns the new array.
+ ```javascript
+ var msg = "ball bat";
+ var n1 = msg.replace(/b/i, "c"); // call bat
+ var n2 = msg.replaceAll(/b/i, "c"); // call cat
+ ```
- ```javascript
- var msg = "Hello John";
- var n = msg.split(/\s/); // ["Hello", "John"]
- ```
+ The `match()` and `matchAll()` methods are used to return the matches when matching a string against a regular expression.
- **[⬆ Back to Top](#table-of-contents)**
+ ```javascript
+ var msg = "Hello John";
+ var n1 = msg.match(/[A-Z]/g); // ["H", "J"]
+ var n2 = msg.matchAll(/[A-Z]/g); // this returns an iterator
+ ```
-156. ### What are modifiers in regular expression
+ The `split()` method is used to split a string into an array of substrings, and returns the new array.
- Modifiers can be used to perform case-insensitive and global searches. Let's list down some of the modifiers,
+ ```javascript
+ var msg = "Hello John";
+ var n = msg.split(/\s/); // ["Hello", "John"]
+ ```
- | Modifier | Description |
- | -------- | ------------------------------------------------------- |
- | i | Perform case-insensitive matching |
- | g | Perform a global match rather than stops at first match |
- | m | Perform multiline matching |
+ **[⬆ Back to Top](#table-of-contents)**
- Let's take an example of global modifier,
+156. ### What are modifiers in regular expression
- ```javascript
- var text = "Learn JS one by one";
- var pattern = /one/g;
- var result = text.match(pattern); // one,one
- ```
+ Modifiers can be used to perform case-insensitive and global searches. Let's list some of the modifiers,
- **[⬆ Back to Top](#table-of-contents)**
+ | Modifier | Description |
+ | -------- | ------------------------------------------------------- |
+ | i | Perform case-insensitive matching |
+ | g | Perform a global match rather than stops at first match |
+ | m | Perform multiline matching |
-157. ### What are regular expression patterns
-
- Regular Expressions provide a group of patterns in order to match characters. Basically they are categorized into 3 types,
-
- 1. **Brackets:** These are used to find a range of characters.
- For example, below are some use cases,
- 1. [abc]: Used to find any of the characters between the brackets(a,b,c)
- 2. [0-9]: Used to find any of the digits between the brackets
- 3. (a|b): Used to find any of the alternatives separated with |
- 2. **Metacharacters:** These are characters with a special meaning.
- For example, below are some use cases,
- 1. \\d: Used to find a digit
- 2. \\s: Used to find a whitespace character
- 3. \\b: Used to find a match at the beginning or ending of a word
- 3. **Quantifiers:** These are useful to define quantities.
- For example, below are some use cases,
- 1. n+: Used to find matches for any string that contains at least one n
- 2. n\*: Used to find matches for any string that contains zero or more occurrences of n
- 3. n?: Used to find matches for any string that contains zero or one occurrences of n
+ Let's take an example of global modifier,
- **[⬆ Back to Top](#table-of-contents)**
+ ```javascript
+ var text = "Learn JS one by one";
+ var pattern = /one/g;
+ var result = text.match(pattern); // one,one
+ ```
-158. ### What is a RegExp object
+ **[⬆ Back to Top](#table-of-contents)**
- RegExp object is a regular expression object with predefined properties and methods. Let's see the simple usage of RegExp object,
+157. ### What are regular expression patterns
+
+ Regular Expressions provide a group of patterns in order to match characters. Basically they are categorized into 3 types,
+
+ 1. **Brackets:** These are used to find a range of characters.
+ For example, below are some use cases,
+ 1. [abc]: Used to find any of the characters between the brackets(a,b,c)
+ 2. [0-9]: Used to find any of the digits between the brackets
+ 3. (a|b): Used to find any of the alternatives separated with |
+ 2. **Metacharacters:** These are characters with a special meaning.
+ For example, below are some use cases,
+ 1. \\d: Used to find a digit
+ 2. \\s: Used to find a whitespace character
+ 3. \\b: Used to find a match at the beginning or ending of a word
+ 3. **Quantifiers:** These are useful to define quantities.
+ For example, below are some use cases,
+ 1. n+: Used to find matches for any string that contains at least one n
+ 2. n\*: Used to find matches for any string that contains zero or more occurrences of n
+ 3. n?: Used to find matches for any string that contains zero or one occurrences of n
- ```javascript
- var regexp = new RegExp("\\w+");
- console.log(regexp);
- // expected output: /\w+/
- ```
+ **[⬆ Back to Top](#table-of-contents)**
- **[⬆ Back to Top](#table-of-contents)**
+158. ### What is a RegExp object
-159. ### How do you search a string for a pattern
+ RegExp object is a regular expression object with predefined properties and methods. Let's see the simple usage of RegExp object,
- You can use the test() method of regular expression in order to search a string for a pattern, and return true or false depending on the result.
+ ```javascript
+ var regexp = new RegExp("\\w+");
+ console.log(regexp);
+ // expected output: /\w+/
+ ```
- ```javascript
- var pattern = /you/;
- console.log(pattern.test("How are you?")); //true
- ```
+ **[⬆ Back to Top](#table-of-contents)**
- **[⬆ Back to Top](#table-of-contents)**
+159. ### How do you search a string for a pattern
-160. ### What is the purpose of exec method
+ You can use the `test()` method of regular expression in order to search a string for a pattern, and return true or false depending on the result.
- The purpose of exec method is similar to test method but it executes a search for a match in a specified string and returns a result array, or null instead of returning true/false.
+ ```javascript
+ var pattern = /you/;
+ console.log(pattern.test("How are you?")); //true
+ ```
- ```javascript
- var pattern = /you/;
- console.log(pattern.exec("How are you?")); //["you", index: 8, input: "How are you?", groups: undefined]
- ```
+ **[⬆ Back to Top](#table-of-contents)**
- **[⬆ Back to Top](#table-of-contents)**
+160. ### What is the purpose of exec method
-161. ### How do you change the style of a HTML element
+ The purpose of exec method is similar to test method but it executes a search for a match in a specified string and returns a result array, or null instead of returning true/false.
- You can change inline style or classname of a HTML element using javascript
+ ```javascript
+ var pattern = /you/;
+ console.log(pattern.exec("How are you?")); //["you", index: 8, input: "How are you?", groups: undefined]
+ ```
- 1. **Using style property:** You can modify inline style using style property
+ **[⬆ Back to Top](#table-of-contents)**
- ```javascript
- document.getElementById("title").style.fontSize = "30px";
- ```
+161. ### How do you change the style of a HTML element
- 2. **Using ClassName property:** It is easy to modify element class using className property
+ You can change inline style or classname of a HTML element using javascript DOM-manipulation
- ```javascript
- document.getElementById("title").className = "custom-title";
- ```
+ 1. **Using style property:** You can modify inline style using style property
- **[⬆ Back to Top](#table-of-contents)**
+ ```javascript
+ document.getElementById("title").style.fontSize = "30px";
+ ```
-162. ### What would be the result of 1+2+'3'
+ 2. **Using ClassName property:** It is easy to modify element class using className property
- The output is going to be `33`. Since `1` and `2` are numeric values, the result of the first two digits is going to be a numeric value `3`. The next digit is a string type value because of that the addition of numeric value `3` and string type value `3` is just going to be a concatenation value `33`. Other operationrs like `3 * '3'` do yield correct results because the string is coerced into a number.
+ ```javascript
+ document.getElementById("title").className = "custom-title";
+ ```
- **[⬆ Back to Top](#table-of-contents)**
+ **[⬆ Back to Top](#table-of-contents)**
-163. ### What is a debugger statement
+162. ### What would be the result of 1+2+'3'
- The debugger statement invokes any available debugging functionality, such as setting a breakpoint. If no debugging functionality is available, this statement has no effect.
- For example, in the below function a debugger statement has been inserted. So
- execution is paused at the debugger statement just like a breakpoint in the script source.
+ The output is going to be `33`. Since `1` and `2` are numeric values, the result of the first two digits is going to be a numeric value `3`. The next digit is a string type value because of that the addition of numeric value `3` and string type value `3` is just going to be a concatenation value `33`. Other operationrs like `3 * '3'` do yield correct results because the string is coerced into a number.
- ```javascript
- function getProfile() {
- // code goes here
- debugger;
- // code goes here
- }
- ```
+ **[⬆ Back to Top](#table-of-contents)**
- **[⬆ Back to Top](#table-of-contents)**
+163. ### What is a debugger statement
-164. ### What is the purpose of breakpoints in debugging
+ The debugger statement invokes any available debugging functionality, such as setting a breakpoint. If no debugging functionality is available, this statement has no effect.
+ For example, in the below function a debugger statement has been inserted. So
+ execution is paused at the debugger statement just like a breakpoint in the script source.
- You can set breakpoints in the javascript code once the debugger statement is executed and the debugger window pops up. At each breakpoint, javascript will stop executing, and let you examine the JavaScript values. After examining values, you can resume the execution of code using the play button.
+ ```javascript
+ function getProfile() {
+ // code goes here
+ debugger;
+ // code goes here
+ }
+ ```
- **[⬆ Back to Top](#table-of-contents)**
+ **[⬆ Back to Top](#table-of-contents)**
-165. ### Can I use reserved words as identifiers
+164. ### What is the purpose of breakpoints in debugging
- No, you cannot use the reserved words as variables, labels, object or function names. Let's see one simple example,
+ You can set breakpoints in the javascript code once the debugger statement is executed and the debugger window pops up. At each breakpoint, javascript will stop executing, and let you examine the JavaScript values. After examining values, you can resume the execution of code using the play button.
- ```javascript
- var else = "hello"; // Uncaught SyntaxError: Unexpected token else
- ```
+ **[⬆ Back to Top](#table-of-contents)**
- **[⬆ Back to Top](#table-of-contents)**
+165. ### Can I use reserved words as identifiers
-166. ### How do you detect a mobile browser
+ No, you cannot use the reserved words as variables, labels, object or function names. Let's see one simple example,
- You can use regex which returns a true or false value depending on whether or not the user is browsing with a mobile.
+ ```javascript
+ var else = "hello"; // Uncaught SyntaxError: Unexpected token else
+ ```
- ```javascript
- window.mobilecheck = function () {
- var mobileCheck = false;
- (function (a) {
- if (
- /(android|bb\d+|meego).+mobile|avantgo|bada\/|blackberry|blazer|compal|elaine|fennec|hiptop|iemobile|ip(hone|od)|iris|kindle|lge |maemo|midp|mmp|mobile.+firefox|netfront|opera m(ob|in)i|palm( os)?|phone|p(ixi|re)\/|plucker|pocket|psp|series(4|6)0|symbian|treo|up\.(browser|link)|vodafone|wap|windows ce|xda|xiino/i.test(
- a
- ) ||
- /1207|6310|6590|3gso|4thp|50[1-6]i|770s|802s|a wa|abac|ac(er|oo|s\-)|ai(ko|rn)|al(av|ca|co)|amoi|an(ex|ny|yw)|aptu|ar(ch|go)|as(te|us)|attw|au(di|\-m|r |s )|avan|be(ck|ll|nq)|bi(lb|rd)|bl(ac|az)|br(e|v)w|bumb|bw\-(n|u)|c55\/|capi|ccwa|cdm\-|cell|chtm|cldc|cmd\-|co(mp|nd)|craw|da(it|ll|ng)|dbte|dc\-s|devi|dica|dmob|do(c|p)o|ds(12|\-d)|el(49|ai)|em(l2|ul)|er(ic|k0)|esl8|ez([4-7]0|os|wa|ze)|fetc|fly(\-|_)|g1 u|g560|gene|gf\-5|g\-mo|go(\.w|od)|gr(ad|un)|haie|hcit|hd\-(m|p|t)|hei\-|hi(pt|ta)|hp( i|ip)|hs\-c|ht(c(\-| |_|a|g|p|s|t)|tp)|hu(aw|tc)|i\-(20|go|ma)|i230|iac( |\-|\/)|ibro|idea|ig01|ikom|im1k|inno|ipaq|iris|ja(t|v)a|jbro|jemu|jigs|kddi|keji|kgt( |\/)|klon|kpt |kwc\-|kyo(c|k)|le(no|xi)|lg( g|\/(k|l|u)|50|54|\-[a-w])|libw|lynx|m1\-w|m3ga|m50\/|ma(te|ui|xo)|mc(01|21|ca)|m\-cr|me(rc|ri)|mi(o8|oa|ts)|mmef|mo(01|02|bi|de|do|t(\-| |o|v)|zz)|mt(50|p1|v )|mwbp|mywa|n10[0-2]|n20[2-3]|n30(0|2)|n50(0|2|5)|n7(0(0|1)|10)|ne((c|m)\-|on|tf|wf|wg|wt)|nok(6|i)|nzph|o2im|op(ti|wv)|oran|owg1|p800|pan(a|d|t)|pdxg|pg(13|\-([1-8]|c))|phil|pire|pl(ay|uc)|pn\-2|po(ck|rt|se)|prox|psio|pt\-g|qa\-a|qc(07|12|21|32|60|\-[2-7]|i\-)|qtek|r380|r600|raks|rim9|ro(ve|zo)|s55\/|sa(ge|ma|mm|ms|ny|va)|sc(01|h\-|oo|p\-)|sdk\/|se(c(\-|0|1)|47|mc|nd|ri)|sgh\-|shar|sie(\-|m)|sk\-0|sl(45|id)|sm(al|ar|b3|it|t5)|so(ft|ny)|sp(01|h\-|v\-|v )|sy(01|mb)|t2(18|50)|t6(00|10|18)|ta(gt|lk)|tcl\-|tdg\-|tel(i|m)|tim\-|t\-mo|to(pl|sh)|ts(70|m\-|m3|m5)|tx\-9|up(\.b|g1|si)|utst|v400|v750|veri|vi(rg|te)|vk(40|5[0-3]|\-v)|vm40|voda|vulc|vx(52|53|60|61|70|80|81|83|85|98)|w3c(\-| )|webc|whit|wi(g |nc|nw)|wmlb|wonu|x700|yas\-|your|zeto|zte\-/i.test(
- a.substr(0, 4)
- )
- )
- mobileCheck = true;
- })(navigator.userAgent || navigator.vendor || window.opera);
- return mobileCheck;
- };
- ```
+ **[⬆ Back to Top](#table-of-contents)**
- **[⬆ Back to Top](#table-of-contents)**
+166. ### How do you detect a mobile browser
-167. ### How do you detect a mobile browser without regexp
+ You can use regex which returns a true or false value depending on whether or not the user is browsing with a mobile.
- You can detect mobile browsers by simply running through a list of devices and checking if the useragent matches anything. This is an alternative solution for RegExp usage,
+ ```javascript
+ window.mobilecheck = function () {
+ var mobileCheck = false;
+ (function (a) {
+ if (
+ /(android|bb\d+|meego).+mobile|avantgo|bada\/|blackberry|blazer|compal|elaine|fennec|hiptop|iemobile|ip(hone|od)|iris|kindle|lge |maemo|midp|mmp|mobile.+firefox|netfront|opera m(ob|in)i|palm( os)?|phone|p(ixi|re)\/|plucker|pocket|psp|series(4|6)0|symbian|treo|up\.(browser|link)|vodafone|wap|windows ce|xda|xiino/i.test(
+ a
+ ) ||
+ /1207|6310|6590|3gso|4thp|50[1-6]i|770s|802s|a wa|abac|ac(er|oo|s\-)|ai(ko|rn)|al(av|ca|co)|amoi|an(ex|ny|yw)|aptu|ar(ch|go)|as(te|us)|attw|au(di|\-m|r |s )|avan|be(ck|ll|nq)|bi(lb|rd)|bl(ac|az)|br(e|v)w|bumb|bw\-(n|u)|c55\/|capi|ccwa|cdm\-|cell|chtm|cldc|cmd\-|co(mp|nd)|craw|da(it|ll|ng)|dbte|dc\-s|devi|dica|dmob|do(c|p)o|ds(12|\-d)|el(49|ai)|em(l2|ul)|er(ic|k0)|esl8|ez([4-7]0|os|wa|ze)|fetc|fly(\-|_)|g1 u|g560|gene|gf\-5|g\-mo|go(\.w|od)|gr(ad|un)|haie|hcit|hd\-(m|p|t)|hei\-|hi(pt|ta)|hp( i|ip)|hs\-c|ht(c(\-| |_|a|g|p|s|t)|tp)|hu(aw|tc)|i\-(20|go|ma)|i230|iac( |\-|\/)|ibro|idea|ig01|ikom|im1k|inno|ipaq|iris|ja(t|v)a|jbro|jemu|jigs|kddi|keji|kgt( |\/)|klon|kpt |kwc\-|kyo(c|k)|le(no|xi)|lg( g|\/(k|l|u)|50|54|\-[a-w])|libw|lynx|m1\-w|m3ga|m50\/|ma(te|ui|xo)|mc(01|21|ca)|m\-cr|me(rc|ri)|mi(o8|oa|ts)|mmef|mo(01|02|bi|de|do|t(\-| |o|v)|zz)|mt(50|p1|v )|mwbp|mywa|n10[0-2]|n20[2-3]|n30(0|2)|n50(0|2|5)|n7(0(0|1)|10)|ne((c|m)\-|on|tf|wf|wg|wt)|nok(6|i)|nzph|o2im|op(ti|wv)|oran|owg1|p800|pan(a|d|t)|pdxg|pg(13|\-([1-8]|c))|phil|pire|pl(ay|uc)|pn\-2|po(ck|rt|se)|prox|psio|pt\-g|qa\-a|qc(07|12|21|32|60|\-[2-7]|i\-)|qtek|r380|r600|raks|rim9|ro(ve|zo)|s55\/|sa(ge|ma|mm|ms|ny|va)|sc(01|h\-|oo|p\-)|sdk\/|se(c(\-|0|1)|47|mc|nd|ri)|sgh\-|shar|sie(\-|m)|sk\-0|sl(45|id)|sm(al|ar|b3|it|t5)|so(ft|ny)|sp(01|h\-|v\-|v )|sy(01|mb)|t2(18|50)|t6(00|10|18)|ta(gt|lk)|tcl\-|tdg\-|tel(i|m)|tim\-|t\-mo|to(pl|sh)|ts(70|m\-|m3|m5)|tx\-9|up(\.b|g1|si)|utst|v400|v750|veri|vi(rg|te)|vk(40|5[0-3]|\-v)|vm40|voda|vulc|vx(52|53|60|61|70|80|81|83|85|98)|w3c(\-| )|webc|whit|wi(g |nc|nw)|wmlb|wonu|x700|yas\-|your|zeto|zte\-/i.test(
+ a.substr(0, 4)
+ )
+ )
+ mobileCheck = true;
+ })(navigator.userAgent || navigator.vendor || window.opera);
+ return mobileCheck;
+ };
+ ```
- ```javascript
- function detectmob() {
- if (
- navigator.userAgent.match(/Android/i) ||
- navigator.userAgent.match(/webOS/i) ||
- navigator.userAgent.match(/iPhone/i) ||
- navigator.userAgent.match(/iPad/i) ||
- navigator.userAgent.match(/iPod/i) ||
- navigator.userAgent.match(/BlackBerry/i) ||
- navigator.userAgent.match(/Windows Phone/i)
- ) {
- return true;
- } else {
- return false;
- }
- }
- ```
+ **[⬆ Back to Top](#table-of-contents)**
- **[⬆ Back to Top](#table-of-contents)**
+167. ### How do you detect a mobile browser without regexp
-168. ### How do you get the image width and height using JS
+ You can detect mobile browsers by simply running through a list of devices and checking if the useragent matches anything. This is an alternative solution for RegExp usage,
- You can programmatically get the image and check the dimensions(width and height) using Javascript.
+ ```javascript
+ function detectmob() {
+ if (
+ navigator.userAgent.match(/Android/i) ||
+ navigator.userAgent.match(/webOS/i) ||
+ navigator.userAgent.match(/iPhone/i) ||
+ navigator.userAgent.match(/iPad/i) ||
+ navigator.userAgent.match(/iPod/i) ||
+ navigator.userAgent.match(/BlackBerry/i) ||
+ navigator.userAgent.match(/Windows Phone/i)
+ ) {
+ return true;
+ } else {
+ return false;
+ }
+ }
+ ```
- ```javascript
- var img = new Image();
- img.onload = function () {
- console.log(this.width + "x" + this.height);
- };
- img.src = "http://www.google.com/intl/en_ALL/images/logo.gif";
- ```
+ **[⬆ Back to Top](#table-of-contents)**
- **[⬆ Back to Top](#table-of-contents)**
+168. ### How do you get the image width and height using JS
-169. ### How do you make synchronous HTTP request
+ You can programmatically get the image and check the dimensions(width and height) using Javascript.
- Browsers provide an XMLHttpRequest object which can be used to make synchronous HTTP requests from JavaScript
+ ```javascript
+ var img = new Image();
+ img.onload = function () {
+ console.log(this.width + "x" + this.height);
+ };
+ img.src = "http://www.google.com/intl/en_ALL/images/logo.gif";
+ ```
- ```javascript
- function httpGet(theUrl) {
- var xmlHttpReq = new XMLHttpRequest();
- xmlHttpReq.open("GET", theUrl, false); // false for synchronous request
- xmlHttpReq.send(null);
- return xmlHttpReq.responseText;
- }
- ```
+ **[⬆ Back to Top](#table-of-contents)**
- **[⬆ Back to Top](#table-of-contents)**
+169. ### How do you make synchronous HTTP request
-170. ### How do you make asynchronous HTTP request
+ Browsers provide an XMLHttpRequest object which can be used to make synchronous HTTP requests from JavaScript.
- Browsers provide an XMLHttpRequest object which can be used to make asynchronous HTTP requests from JavaScript by passing the 3rd parameter as true.
+ ```javascript
+ function httpGet(theUrl) {
+ var xmlHttpReq = new XMLHttpRequest();
+ xmlHttpReq.open("GET", theUrl, false); // false for synchronous request
+ xmlHttpReq.send(null);
+ return xmlHttpReq.responseText;
+ }
+ ```
- ```javascript
- function httpGetAsync(theUrl, callback) {
- var xmlHttpReq = new XMLHttpRequest();
- xmlHttpReq.onreadystatechange = function () {
- if (xmlHttpReq.readyState == 4 && xmlHttpReq.status == 200)
- callback(xmlHttpReq.responseText);
- };
- xmlHttpReq.open("GET", theUrl, true); // true for asynchronous
- xmlHttpReq.send(null);
- }
- ```
+ **[⬆ Back to Top](#table-of-contents)**
- **[⬆ Back to Top](#table-of-contents)**
+170. ### How do you make asynchronous HTTP request
-171. ### How do you convert date to another timezone in javascript
+ Browsers provide an XMLHttpRequest object which can be used to make asynchronous HTTP requests from JavaScript by passing the 3rd parameter as true.
- You can use the toLocaleString() method to convert dates in one timezone to another. For example, let's convert current date to British English timezone as below,
+ ```javascript
+ function httpGetAsync(theUrl, callback) {
+ var xmlHttpReq = new XMLHttpRequest();
+ xmlHttpReq.onreadystatechange = function () {
+ if (xmlHttpReq.readyState == 4 && xmlHttpReq.status == 200)
+ callback(xmlHttpReq.responseText);
+ };
+ xmlHttpReq.open("GET", theUrl, true); // true for asynchronous
+ xmlHttpReq.send(null);
+ }
+ ```
- ```javascript
- console.log(new Date().toLocaleString("en-GB", { timeZone: "UTC" })); //29/06/2019, 09:56:00
- ```
+ Today this is considered deprecated, because an async `fetch` call (in browsers later than 2016) is simpler and more robust.
- **[⬆ Back to Top](#table-of-contents)**
+ **[⬆ Back to Top](#table-of-contents)**
-172. ### What are the properties used to get size of window
+171. ### How do you convert date to another timezone in javascript
- You can use innerWidth, innerHeight, clientWidth, clientHeight properties of windows, document element and document body objects to find the size of a window. Let's use them combination of these properties to calculate the size of a window or document,
+ You can use the toLocaleString() method to convert dates in one timezone to another. For example, let's convert current date to British English timezone as below,
- ```javascript
- var width =
- window.innerWidth ||
- document.documentElement.clientWidth ||
- document.body.clientWidth;
-
- var height =
- window.innerHeight ||
- document.documentElement.clientHeight ||
- document.body.clientHeight;
- ```
+ ```javascript
+ console.log(new Date().toLocaleString("en-GB", { timeZone: "UTC" })); //29/06/2019, 09:56:00
+ ```
- **[⬆ Back to Top](#table-of-contents)**
+ **[⬆ Back to Top](#table-of-contents)**
-173. ### What is a conditional operator in javascript
+172. ### What are the properties used to get size of window
- The conditional (ternary) operator is the only JavaScript operator that takes three operands which acts as a shortcut for if statements.
+ You can use innerWidth, innerHeight, clientWidth, clientHeight properties of windows, document element and document body objects to find the size of a window. Let's use them combination of these properties to calculate the size of a window or document,
- ```javascript
- var isAuthenticated = false;
- console.log(
- isAuthenticated ? "Hello, welcome" : "Sorry, you are not authenticated"
- ); //Sorry, you are not authenticated
- ```
+ ```javascript
+ var width =
+ window.innerWidth ||
+ document.documentElement.clientWidth ||
+ document.body.clientWidth;
+
+ var height =
+ window.innerHeight ||
+ document.documentElement.clientHeight ||
+ document.body.clientHeight;
+ ```
- **[⬆ Back to Top](#table-of-contents)**
+ **[⬆ Back to Top](#table-of-contents)**
-174. ### Can you apply chaining on conditional operator
+173. ### What is a conditional operator in javascript
- Yes, you can apply chaining on conditional operators similar to **if … else if … else if … else** chain. The syntax is going to be as below,
+ The conditional (ternary) operator is the only JavaScript operator that takes three operands which acts as a shortcut for `if` statements.
- ```javascript
- function traceValue(someParam) {
- return condition1
- ? value1
- : condition2
- ? value2
- : condition3
- ? value3
- : value4;
- }
+ ```javascript
+ var isAuthenticated = false;
+ console.log(
+ isAuthenticated ? "Hello, welcome" : "Sorry, you are not authenticated"
+ ); // Sorry, you are not authenticated
+ ```
- // The above conditional operator is equivalent to:
+ **[⬆ Back to Top](#table-of-contents)**
- function traceValue(someParam) {
- if (condition1) {
- return value1;
- } else if (condition2) {
- return value2;
- } else if (condition3) {
- return value3;
- } else {
- return value4;
- }
- }
- ```
+174. ### Can you apply chaining on conditional operator
- **[⬆ Back to Top](#table-of-contents)**
+ Yes, you can apply chaining on conditional operators similar to **`if … else if … else if … else`** chain. The syntax is going to be as below,
-175. ### What are the ways to execute javascript after page load
+ ```javascript
+ function traceValue(someParam) {
+ return condition1
+ ? value1
+ : condition2
+ ? value2
+ : condition3
+ ? value3
+ : value4;
+ }
- You can execute javascript after page load in many different ways,
+ // The above conditional operator is equivalent to:
- 1. **window.onload:**
+ function traceValue(someParam) {
+ if (condition1) {
+ return value1;
+ } else if (condition2) {
+ return value2;
+ } else if (condition3) {
+ return value3;
+ } else {
+ return value4;
+ }
+ }
+ ```
- ```javascript
- window.onload = function ...
- ```
+ **[⬆ Back to Top](#table-of-contents)**
- 2. **document.onload:**
+175. ### What are the ways to execute javascript after a page load
- ```javascript
- document.onload = function ...
- ```
+ You can execute javascript after page load in many different ways,
- 3. **body onload:**
+ 1. **window.onload:**
- ```javascript
-
- ```
+ ```javascript
+ window.onload = function ...
+ ```
- **[⬆ Back to Top](#table-of-contents)**
+ 2. **document.onload:**
-176. ### What is the difference between proto and prototype
+ ```javascript
+ document.onload = function ...
+ ```
- The `__proto__` object is the actual object that is used in the lookup chain to resolve methods, etc. Whereas `prototype` is the object that is used to build `__proto__` when you create an object with new.
+ 3. **body onload:**
- ```javascript
- new Employee().__proto__ === Employee.prototype;
- new Employee().prototype === undefined;
- ```
+ ```javascript
+
+ ```
- There are few more differences,
+ **[⬆ Back to Top](#table-of-contents)**
- | feature | Prototype | proto |
- | ---------- | ------------------------------------------------------------ | ---------------------------------------------------------- |
- | Access | All the function constructors have prototype properties. | All the objects have \_\_proto\_\_ property |
- | Purpose | Used to reduce memory wastage with a single copy of function | Used in lookup chain to resolve methods, constructors etc. |
- | ECMAScript | Introduced in ES6 | Introduced in ES5 |
- | Usage | Frequently used | Rarely used |
+176. ### What is the difference between proto and prototype
- **[⬆ Back to Top](#table-of-contents)**
+ The `__proto__` object is the actual object that is used in the lookup chain to resolve methods, etc. Whereas `prototype` is the object that is used to build `__proto__` when you create an object with the `new` operator (a special variant of a function call).
-177. ### Can you give an example of when you really need a semicolon
+ ```javascript
+ new Employee().__proto__ === Employee.prototype;
+ new Employee().prototype === undefined;
+ ```
- It is recommended to use semicolons after every statement in JavaScript. For example, in the below case it throws an error ".. is not a function" at runtime due to missing semicolon.
+ There are few more differences,
- ```javascript
- // define a function
- var fn = (function () {
- //...
- })(
- // semicolon missing at this line
-
- // then execute some code inside a closure
- function () {
- //...
- }
- )();
- ```
+ | feature | Prototype | proto |
+ | ---------- | ------------------------------------------------------------ | ---------------------------------------------------------- |
+ | Access | All function constructors have prototype properties. | All objects have \_\_proto\_\_ property |
+ | Purpose | Used to reduce memory wastage with a single copy of function | Used in lookup chain to resolve methods, constructors etc. |
+ | ECMAScript | Introduced in ES6 | Introduced in ES5 |
+ | Usage | Frequently used | Rarely used |
- and it will be interpreted as
+ **[⬆ Back to Top](#table-of-contents)**
- ```javascript
- var fn = (function () {
- //...
- })(function () {
- //...
- })();
- ```
+177. ### Can you give an example of when you really need a semicolon
- In this case, we are passing the second function as an argument to the first function and then trying to call the result of the first function call as a function. Hence, the second function will fail with a "... is not a function" error at runtime.
+ It is recommended to use semicolons after every statement in JavaScript. For example, in the below case (that is an IIFE = Immediately Invoked Function Expression) it throws an error ".. is not a function" at runtime due to missing semicolon.
- **[⬆ Back to Top](#table-of-contents)**
+ ```javascript
+ // define a function
+ var fn = (function () {
+ //...
+ })(
+ // semicolon missing at this line
-178. ### What is a freeze method
+ // then execute some code inside a closure
+ function () {
+ //...
+ }
+ )();
+ ```
- The **freeze()** method is used to freeze an object. Freezing an object does not allow adding new properties to an object, prevents removing, and prevents changing the enumerability, configurability, or writability of existing properties. i.e. It returns the passed object and does not create a frozen copy.
+ and it will be interpreted as
- ```javascript
- const obj = {
- prop: 100,
- };
+ ```javascript
+ var fn = (function () {
+ //...
+ })(function () {
+ //...
+ })();
+ ```
- Object.freeze(obj);
- obj.prop = 200; // Throws an error in strict mode
+ In this case, we are passing the second function as an argument to the first function and then trying to call the result of the first function call as a function. Hence, the second function will fail with a "... is not a function" error at runtime.
- console.log(obj.prop); //100
- ```
+ **[⬆ Back to Top](#table-of-contents)**
- Remember freezing is only applied to the top-level properties in objects but not for nested objects.
- For example, let's try to freeze user object which has employment details as nested object and observe that details have been changed.
+178. ### What is the freeze method
- ```javascript
- const user = {
- name: "John",
- employment: {
- department: "IT",
- },
- };
+ The **`freeze()`** method is used to freeze an object. Freezing an object does not allow adding new properties to an object, prevents removing, and prevents changing the enumerability, configurability, or writability of existing properties. i.e. It returns the passed object and does not create a frozen copy.
- Object.freeze(user);
- user.employment.department = "HR";
- ```
+ ```javascript
+ const obj = {
+ prop: 100,
+ };
- **Note:** It causes a TypeError if the argument passed is not an object.
+ Object.freeze(obj);
+ obj.prop = 200; // Throws an error in strict mode
- **[⬆ Back to Top](#table-of-contents)**
+ console.log(obj.prop); //100
+ ```
-179. ### What is the purpose of freeze method
+ Remember freezing is only applied to the top-level properties in objects but not for nested objects.
+ For example, let's try to freeze user object which has employment details as nested object and observe that details have been changed.
- Below are the main benefits of using freeze method,
+ ```javascript
+ const user = {
+ name: "John",
+ employment: {
+ department: "IT",
+ },
+ };
- 1. It is used for freezing objects and arrays.
- 2. It is used to make an object immutable.
+ Object.freeze(user);
+ user.employment.department = "HR";
+ ```
- **[⬆ Back to Top](#table-of-contents)**
+ **Note:** It causes a TypeError if the argument passed is not an object.
-180. ### Why do I need to use freeze method
+ **[⬆ Back to Top](#table-of-contents)**
- In the Object-oriented paradigm, an existing API contains certain elements that are not intended to be extended, modified, or re-used outside of their current context. Hence it works as the `final` keyword which is used in various languages.
+179. ### What is the purpose of the freeze method
- **[⬆ Back to Top](#table-of-contents)**
+ Below are the main benefits of using freeze method,
-181. ### How do you detect a browser language preference
+ 1. It is used for freezing objects and arrays.
+ 2. It is used to make an object immutable.
- You can use navigator object to detect a browser language preference as below,
+ **[⬆ Back to Top](#table-of-contents)**
- ```javascript
- var language =
- (navigator.languages && navigator.languages[0]) || // Chrome / Firefox
- navigator.language || // All browsers
- navigator.userLanguage; // IE <= 10
+180. ### Why do I need to use the freeze method
- console.log(language);
- ```
+ In the Object-oriented paradigm, an existing API contains certain elements that are not intended to be extended, modified, or re-used outside of their current context. Hence it works as the `final` keyword which is used in various languages.
- **[⬆ Back to Top](#table-of-contents)**
+ **[⬆ Back to Top](#table-of-contents)**
-182. ### How to convert string to title case with javascript
+181. ### How do you detect a browser language preference
- Title case means that the first letter of each word is capitalized. You can convert a string to title case using the below function,
+ You can use the navigator object to detect a browser language preference as below,
- ```javascript
- function toTitleCase(str) {
- return str.replace(/\w\S*/g, function (txt) {
- return txt.charAt(0).toUpperCase() + txt.substring(1).toLowerCase();
- });
- }
- toTitleCase("good morning john"); // Good Morning John
- ```
+ ```javascript
+ var language =
+ (navigator.languages && navigator.languages[0]) || // Chrome / Firefox
+ navigator.language || // All browsers
+ navigator.userLanguage; // IE <= 10
- **[⬆ Back to Top](#table-of-contents)**
+ console.log(language);
+ ```
-183. ### How do you detect javascript disabled in the page
+ **[⬆ Back to Top](#table-of-contents)**
- You can use the `