{"id":20076277,"url":"https://github.com/aakashdeveloper/javascript-interview-question","last_synced_at":"2025-10-20T07:40:01.399Z","repository":{"id":98117041,"uuid":"307894304","full_name":"Aakashdeveloper/JavaScript-Interview-Question","owner":"Aakashdeveloper","description":"JavaScript-Interview-Question","archived":false,"fork":false,"pushed_at":"2024-05-11T07:00:09.000Z","size":568,"stargazers_count":50,"open_issues_count":1,"forks_count":23,"subscribers_count":3,"default_branch":"master","last_synced_at":"2025-01-13T00:49:27.414Z","etag":null,"topics":[],"latest_commit_sha":null,"homepage":null,"language":"HTML","has_issues":true,"has_wiki":null,"has_pages":null,"mirror_url":null,"source_name":null,"license":null,"status":null,"scm":"git","pull_requests_enabled":true,"icon_url":"https://github.com/Aakashdeveloper.png","metadata":{"files":{"readme":"README.md","changelog":null,"contributing":null,"funding":null,"license":null,"code_of_conduct":null,"threat_model":null,"audit":null,"citation":null,"codeowners":null,"security":null,"support":null,"governance":null,"roadmap":null,"authors":null,"dei":null,"publiccode":null,"codemeta":null}},"created_at":"2020-10-28T03:16:29.000Z","updated_at":"2024-10-09T18:15:26.000Z","dependencies_parsed_at":"2024-05-11T08:22:05.547Z","dependency_job_id":"ab1915b7-233a-47ce-9fb2-99fd6c33e2fd","html_url":"https://github.com/Aakashdeveloper/JavaScript-Interview-Question","commit_stats":null,"previous_names":[],"tags_count":0,"template":false,"template_full_name":null,"repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/Aakashdeveloper%2FJavaScript-Interview-Question","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/Aakashdeveloper%2FJavaScript-Interview-Question/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/Aakashdeveloper%2FJavaScript-Interview-Question/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/Aakashdeveloper%2FJavaScript-Interview-Question/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/Aakashdeveloper","download_url":"https://codeload.github.com/Aakashdeveloper/JavaScript-Interview-Question/tar.gz/refs/heads/master","host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":241509624,"owners_count":19974070,"icon_url":"https://github.com/github.png","version":null,"created_at":"2022-05-30T11:31:42.601Z","updated_at":"2022-07-04T15:15:14.044Z","host_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub","repositories_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories","repository_names_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repository_names","owners_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners"}},"keywords":[],"created_at":"2024-11-13T15:02:08.466Z","updated_at":"2025-10-20T07:40:01.323Z","avatar_url":"https://github.com/Aakashdeveloper.png","language":"HTML","funding_links":[],"categories":[],"sub_categories":[],"readme":"# JavaScript Interview Questions\n\n*Click \u003cimg src=\"assets/star.png\" width=\"18\" height=\"18\" align=\"absmiddle\" title=\"Star\" /\u003e if you like the project. Pull Request are highly appreciated.*\n\n## Table of Contents\n\n* *[ES6 Interview Questions and Answers](es6-questions.md)*\n* *[Programming in JavaScript](javascript-programs.md)*\n\n\u003cbr/\u003e\n\n|Sl.No| Questions                                                                         |\n|-----|-----------------------------------------------------------------------------------|\n| 01.|[What is difference between document.getElementById() and document.uerySelector()?](#q-what-is-difference-between-document-getelementbyid-and-document-ueryselector)|\n| 02.|[When to use reduce(), map(), foreach() and filter() in JavaScript?](#q-when-to-use-reduce-map-foreach-and-filter-in-javascript)|\n| 03.|[What is Hoisting in JavaScript?](#q-what-is-hoisting-in-javascript)|\n| 04.|[What are closures?](#q-what-are-closures)|\n| 05.|[How do you clone an object in JavaScript?](#q-how-do-you-clone-an-object-in-javascript)|\n| 06.|[What are the possible ways to create objects in JavaScript?](#q-what-are-the-possible-ways-to-create-objects-in-javascript)|\n| 07.|[What are the javascript data types?](#q-what-are-the-javascript-data-types)|\n| 08.|[What are global variables?](#q-what-are-global-variables)|\n| 09.|[What is variable shadowing in javascript?](#q-what-is-variable-shadowing-in-javascript)|\n| 10.|[What is an event flow?](#q-what-is-an-event-flow)|\n| 11.|[What is event bubbling?](#q-what-is-event-bubbling)|\n| 12.|[What is event capturing?](#q-what-is-event-capturing)|\n| 13.|[What is prototype chain?](#q-what-is-prototype-chain)|\n| 14.|[What is the difference between Call, Apply and Bind?](#q-what-is-the-difference-between-call-apply-and-bind)|\n| 15.|[What is the difference between == and === operators?](#q-what-is-the-difference-between-and-operators)|\n| 16.|[What is a first class function?](#q-what-is-a-first-class-function)|\n| 17.|[What is a higher order function?](#q-what-is-a-higher-order-function)|\n| 18.|[What is a unary function?](#q-what-is-a-unary-function)|\n| 19.|[What is currying function?](#q-what-is-currying-function)|\n| 20.|[What is a pure function?](#q-what-is-a-pure-function)|\n| 21.|[What is memoization in JavaScript?](#q-what-is-memoization-in-javascript)|\n| 22.|[What is a service worker?](#q-what-is-a-service-worker)|\n| 23.|[How do you manipulate DOM using service worker?](#q-how-do-you-manipulate-dom-using-service-worker)|\n| 24.|[How do you reuse information across service worker restarts?](#q-how-do-you-reuse-information-across-service-worker-restarts)|\n| 25.|[What is a post message?](#q-what-is-a-post-message)|\n| 26.|[What is a web-storage event and its event handler?](#q-what-is-a-web-storage-event-and-its-event-handler)|\n| 27.|[How to use Web Workers in javascript?](#q-how-to-use-web-workers-in-javascript)|\n| 28.|[What are the restrictions of web workers on DOM?](#q-what-are-the-restrictions-of-web-workers-on-dom)|\n| 29.|[What is a promise?](#q-what-is-a-promise)|\n| 30.|[What is a callback function?](#q-what-is-a-callback-function)|\n| 31.|[Why do we need callbacks?](#q-why-do-we-need-callbacks)|\n| 32.|[What is a callback hell?](#q-what-is-a-callback-hell)|\n| 33.|[What is server-sent events?](#q-what-is-server-sent-events)|\n| 34.|[What is callback in callback?](#q-what-is-callback-in-callback)|\n| 35.|[What is promise chaining?](#q-what-is-promise-chaining)|\n| 36.|[What is promise.all()?](#q-what-is-promiseall)|\n| 37.|[What is the purpose of race method in promise?](#q-what-is-the-purpose-of-race-method-in-promise)|\n| 38.|[What is a strict mode in javascript?](#q-what-is-a-strict-mode-in-javascript)|\n| 39.|[What is the purpose of double exclamation?](#q-what-is-the-purpose-of-double-exclamation)|\n| 40.|[What is the purpose of delete operator?](#q-what-is-the-purpose-of-delete-operator)|\n| 41.|[What is typeof operator?](#q-what-is-typeof-operator)|\n| 42.|[What is undefined property?](#q-what-is-undefined-property)|\n| 43.|[What is the difference between null and undefined?](#q-what-is-the-difference-between-null-and-undefined)|\n| 44.|[What is eval?](#q-what-is-eval)|\n| 45.|[What is the difference between window and document?](#q-what-is-the-difference-between-window-and-document)|\n| 46.|[How do you access history in javascript?](#q-how-do-you-access-history-in-javascript)|\n| 47.|[What is isNaN?](#q-what-is-isnan)|\n| 48.|[What are the differences between undeclared and undefined variables?](#q-what-are-the-differences-between-undeclared-and-undefined-variables)|\n| 49.|[What is NaN property?](#q-what-is-nan-property)|\n| 50.|[What is the purpose of isFinite function?](#q-what-is-the-purpose-of-isfinite-function)|\n| 51.|[How do you submit a form using JavaScript?](#q-how-do-you-submit-a-form-using-javascript)|\n| 52.|[How do you find operating system details?](#q-how-do-you-find-operating-system-details)|\n| 53.|[What is the difference between document load and DOMContentLoaded events?](#q-what-is-the-difference-between-document-load-and-domcontentloaded-events)|\n| 54.|[What is the difference between native, host and user objects?](#q-what-is-the-difference-between-native-host-and-user-objects)|\n| 55.|[What are the pros and cons of promises over callbacks?](#q-what-are-the-pros-and-cons-of-promises-over-callbacks)|\n| 56.|[What is the difference between an attribute and a property?](#q-what-is-the-difference-between-an-attribute-and-a-property)|\n| 57.|[What is same-origin policy?](#q-what-is-same-origin-policy)|\n| 58.|[What is the purpose of void(0)?](#q-what-is-the-purpose-of-void-0)|\n| 59.|[Is JavaScript a compiled or interpreted language?](#q-is-javascript-a-compiled-or-interpreted-language)|\n| 60.|[Is JavaScript a case-sensitive language?](#q-is-javascript-a-case-sensitive-language)|\n| 61.|[What are events?](#q-what-are-events)|\n| 62.|[What is the use of preventDefault method?](#q-what-is-the-use-of-preventdefault-method)|\n| 63.|[What is the use of stopPropagation method?](#q-what-is-the-use-of-stoppropagation-method)|\n| 64.|[What are the steps involved in return false usage?](#q-what-are-the-steps-involved-in-return-false-usage)|\n| 65.|[What is BOM?](#q-what-is-bom)|\n| 66.|[What is the use of setTimeout?](#q-what-is-the-use-of-settimeout)|\n| 67.|[What is the use of setInterval?](#q-what-is-the-use-of-setinterval)|\n| 68.|[Why is JavaScript treated as Single threaded?](#q-why-is-javascript-treated-as-single-threaded)|\n| 69.|[What is an event delegation?](#q-what-is-an-event-delegation)|\n| 70.|[What is the purpose JSON stringify?](#q-what-is-the-purpose-json-stringify)|\n| 71.|[How do you parse JSON string?](#q-how-do-you-parse-json-string)|\n| 72.|[What is the purpose of clearTimeout method?](#q-what-is-the-purpose-of-cleartimeout-method)|\n| 73.|[What is the purpose of clearInterval method?](#q-what-is-the-purpose-of-clearinterval-method)|\n| 74.|[How do you redirect new page in javascript?](#q-how-do-you-redirect-new-page-in-javascript)|\n| 75.|[How do you check whether a string contains a substring?](#q-how-do-you-check-whether-a-string-contains-a-substring)|\n| 76.|[How do you validate an email in javascript?](#q-how-do-you-validate-an-email-in-javascript)|\n| 77.|[How do you get the current url with javascript?](#q-how-do-you-get-the-current-url-with-javascript)|\n| 78.|[What are the various url properties of location object?](#q-what-are-the-various-url-properties-of-location-object)|\n| 79.|[How do get uery string values in javascript?](#q-how-do-get-uery-string-values-in-javascript)|\n| 80.|[How do you check if a key exists in an object?](#q-how-do-you-check-if-a-key-exists-in-an-object)|\n| 81.|[How do you loop through or enumerate javascript object?](#q-how-do-you-loop-through-or-enumerate-javascript-object)|\n| 82.|[How do you test for an empty object?](#q-how-do-you-test-for-an-empty-object)|\n| 83.|[What is an arguments object?](#q-what-is-an-arguments-object)|\n| 84.|[How do you make first letter of the string in an uppercase?](#q-how-do-you-make-first-letter-of-the-string-in-an-uppercase)|\n| 85.|[What are the pros and cons of for loop?](#q-what-are-the-pros-and-cons-of-for-loop)|\n| 86.|[How do you display the current date in javascript?](#q-how-do-you-display-the-current-date-in-javascript)|\n| 87.|[How do you compare two date objects?](#q-how-do-you-compare-two-date-objects)|\n| 88.|[How do you check if a string starts with another string?](#q-how-do-you-check-if-a-string-starts-with-another-string)|\n| 89.|[How do you trim a string in javascript?](#q-how-do-you-trim-a-string-in-javascript)|\n| 90.|[How do you add a key value pair in javascript?](#q-how-do-you-add-a-key-value-pair-in-javascript)|\n| 91.|[How do you assign default values to variables?](#q-how-do-you-assign-default-values-to-variables)|\n| 92.|[Can we define properties for functions?](#q-can-we-define-properties-for-functions)|\n| 93.|[What is the way to find the number of parameters expected by a function?](#q-what-is-the-way-to-find-the-number-of-parameters-expected-by-a-function)|\n| 94.|[What are break and continue statements?](#q-what-are-break-and-continue-statements)|\n| 95.|[What are js labels?](#q-what-are-js-labels)|\n| 96.|[What are the benefits of keeping declarations at the top?](#q-what-are-the-benefits-of-keeping-declarations-at-the-top)|\n| 97.|[What are the benefits of initializing variables?](#q-what-are-the-benefits-of-initializing-variables)|\n| 98.|[What are the recommendations to create new object?](#q-what-are-the-recommendations-to-create-new-object)|\n| 99.|[How do you define JSON arrays?](#q-how-do-you-define-json-arrays)|\n| 100.|[How do you generate random integers?](#q-how-do-you-generate-random-integers)|\n| 101.|[Can you write a random integers function to print integers with in a range?](#q-can-you-write-a-random-integers-function-to-print-integers-with-in-a-range)|\n| 102.|[What are the string methods available in Regular expression?](#q-what-are-the-string-methods-available-in-regular-expression)|\n| 103.|[What are modifiers in regular expression?](#q-what-are-modifiers-in-regular-expression)|\n| 104.|[What are regular expression patterns?](#q-what-are-regular-expression-patterns)|\n| 105.|[What is a RegExp object?](#q-what-is-a-regexp-object)|\n| 106.|[How do you search a string for a pattern?](#q-how-do-you-search-a-string-for-a-pattern)|\n| 107.|[What is the purpose of exec method?](#q-what-is-the-purpose-of-exec-method)|\n| 108.|[How do you change style of a HTML element?](#q-how-do-you-change-style-of-a-html-element)|\n| 109.|[What is a debugger statement?](#q-what-is-a-debugger-statement)|\n| 110.|[What is the purpose of breakpoints in debugging?](#q-what-is-the-purpose-of-breakpoints-in-debugging)|\n| 111.|[Can I use reserved words as identifiers?](#q-can-i-use-reserved-words-as-identifiers)|\n| 112.|[How do you detect a mobile browser without regexp?](#q-how-do-you-detect-a-mobile-browser-without-regexp)|\n| 113.|[How do you get the image width and height using JS?](#q-how-do-you-get-the-image-width-and-height-using-js)|\n| 114.|[How do you make synchronous HTTP reuest?](#q-how-do-you-make-synchronous-http-reuest)|\n| 115.|[How do you make asynchronous HTTP reuest?](#q-how-do-you-make-asynchronous-http-reuest)|\n| 116.|[How do you convert date to another timezone in javascript?](#q-how-do-you-convert-date-to-another-timezone-in-javascript)|\n| 117.|[What are the properties used to get size of window?](#q-what-are-the-properties-used-to-get-size-of-window)|\n| 118.|[What is a conditional operator in javascript?](#q-what-is-a-conditional-operator-in-javascript)|\n| 119.|[Can you apply chaining on conditional operator?](#q-can-you-apply-chaining-on-conditional-operator)|\n| 120.|[What are the ways to execute javascript after page load?](#q-what-are-the-ways-to-execute-javascript-after-page-load)|\n| 121.|[What is the difference between proto and prototype?](#q-what-is-the-difference-between-proto-and-prototype)|\n| 122.|[Give an example where do you really need semicolon?](#q-give-an-example-where-do-you-really-need-semicolon)|\n| 123.|[What is a freeze method?](#q-what-is-a-freeze-method)|\n| 124.|[What is the purpose of freeze method?](#q-what-is-the-purpose-of-freeze-method)|\n| 125.|[Why do I need to use freeze method?](#q-why-do-i-need-to-use-freeze-method)|\n| 126.|[How do you detect a browser language preference?](#q-how-do-you-detect-a-browser-language-preference)|\n| 127.|[How to convert string to title case with javascript?](#q-how-to-convert-string-to-title-case-with-javascript)|\n| 128.|[How do you detect javascript disabled in the page?](#q-how-do-you-detect-javascript-disabled-in-the-page)|\n| 129.|[What are various operators supported by javascript?](#q-what-are-various-operators-supported-by-javascript)|\n| 130.|[What is a rest parameter?](#q-what-is-a-rest-parameter)|\n| 131.|[What happens if you do not use rest parameter as a last argument?](#q-what-happens-if-you-do-not-use-rest-parameter-as-a-last-argument)|\n| 132.|[What are the bitwise operators available in javascript?](#q-what-are-the-bitwise-operators-available-in-javascript)|\n| 133.|[How do you determine whether object is frozen or not?](#q-how-do-you-determine-whether-object-is-frozen-or-not)|\n| 134.|[How do you determine two values same or not using object?](#q-how-do-you-determine-two-values-same-or-not-using-object)|\n| 135.|[What is the purpose of using object is method?](#q-what-is-the-purpose-of-using-object-is-method)|\n| 136.|[How do you copy properties from one object to other?](#q-how-do-you-copy-properties-from-one-object-to-other)|\n| 137.|[What are the applications of assign method?](#q-what-are-the-applications-of-assign-method)|\n| 138.|[What is a proxy object?](#q-what-is-a-proxy-object)|\n| 139.|[What is the purpose of seal method?](#q-what-is-the-purpose-of-seal-method)|\n| 140.|[What are the applications of seal method?](#q-what-are-the-applications-of-seal-method)|\n| 141.|[What are the differences between freeze and seal methods?](#q-what-are-the-differences-between-freeze-and-seal-methods)|\n| 142.|[How do you determine if an object is sealed or not?](#q-how-do-you-determine-if-an-object-is-sealed-or-not)|\n| 143.|[How do you get enumerable key and value pairs?](#q-how-do-you-get-enumerable-key-and-value-pairs)|\n| 144.|[What is the main difference between Object.values and Object.entries method?](#q-what-is-the-main-difference-between-objectvalues-and-objectentries-method)|\n| 145.|[How can you get the list of keys of any object?](#q-how-can-you-get-the-list-of-keys-of-any-object)|\n| 146.|[How do you create an object with prototype?](#q-how-do-you-create-an-object-with-prototype)|\n| 147.|[What is a WeakSet?](#q-what-is-a-weakset)|\n| 148.|[What are the differences between WeakSet and Set?](#q-what-are-the-differences-between-weakset-and-set)|\n| 149.|[List down the collection of methods available on WeakSet?](#q-list-down-the-collection-of-methods-available-on-weakset)|\n| 150.|[What is a WeakMap?](#q-what-is-a-weakmap)|\n| 151.|[What are the differences between WeakMap and Map?](#q-what-are-the-differences-between-weakmap-and-map)|\n| 152.|[List down the collection of methods available on WeakMap?](#q-list-down-the-collection-of-methods-available-on-weakmap)|\n| 153.|[What is the purpose of uneval?](#q-what-is-the-purpose-of-uneval)|\n| 154.|[How do you encode an URL?](#q-how-do-you-encode-an-url)|\n| 155.|[How do you decode an URL?](#q-how-do-you-decode-an-url)|\n| 156.|[How do you print the contents of web page?](#q-how-do-you-print-the-contents-of-web-page)|\n| 157.|[What is the difference between uneval and eval?](#q-what-is-the-difference-between-uneval-and-eval)|\n| 158.|[What is an anonymous function?](#q-what-is-an-anonymous-function)|\n| 159.|[What is the precedence order between local and global variables?](#q-what-is-the-precedence-order-between-local-and-global-variables)|\n| 160.|[What are javascript accessors?](#q-what-are-javascript-accessors)|\n| 161.|[How do you define property on Object constructor?](#q-how-do-you-define-property-on-object-constructor)|\n| 162.|[What is the difference between get and defineProperty?](#q-what-is-the-difference-between-get-and-defineproperty)|\n| 163.|[What are the advantages of Getters and Setters?](#q-what-are-the-advantages-of-getters-and-setters)|\n| 164.|[Can I add getters and setters using defineProperty method?](#q-can-i-add-getters-and-setters-using-defineproperty-method)|\n| 165.|[What is the purpose of switch-case?](#q-what-is-the-purpose-of-switch-case)|\n| 166.|[What are the conventions to be followed for the usage of swtich case?](#q-what-are-the-conventions-to-be-followed-for-the-usage-of-swtich-case)|\n| 167.|[What are the different ways to access object properties?](#q-what-are-the-different-ways-to-access-object-properties)|\n| 168.|[What are the function parameter rules?](#q-what-are-the-function-parameter-rules)|\n| 169.|[What is an error object?](#q-what-is-an-error-object)|\n| 170.|[When you get a syntax error?](#q-when-you-get-a-syntax-error)|\n| 171.|[What are the different error names from error object?](#q-what-are-the-different-error-names-from-error-object)|\n| 172.|[What are the various statements in error handling?](#q-what-are-the-various-statements-in-error-handling)|\n| 173.|[What are the two types of loops in javascript?](#q-what-are-the-two-types-of-loops-in-javascript)|\n| 174.|[What is an Intl object?](#q-what-is-an-intl-object)|\n| 175.|[How do you perform language specific date and time formatting?](#q-how-do-you-perform-language-specific-date-and-time-formatting)|\n| 176.|[What is an Iterator?](#q-what-is-an-iterator)|\n| 177.|[What is a decorator?](#q-what-is-a-decorator)|\n| 178.|[What are the properties of Intl object?](#q-what-are-the-properties-of-intl-object)|\n| 179.|[What is an Unary operator?](#q-what-is-an-unary-operator)|\n| 180.|[How do you sort elements in an array?](#q-how-do-you-sort-elements-in-an-array)|\n| 181.|[What is the purpose of compareFunction while sorting arrays?](#q-what-is-the-purpose-of-comparefunction-while-sorting-arrays)|\n| 182.|[How do you reversing an array?](#q-how-do-you-reversing-an-array)|\n| 183.|[How do you find min and max value in an array?](#q-how-do-you-find-min-and-max-value-in-an-array)|\n| 184.|[How do you find min and max values without Math functions?](#q-how-do-you-find-min-and-max-values-without-math-functions)|\n| 185.|[What is an empty statement and purpose of it?](#q-what-is-an-empty-statement-and-purpose-of-it)|\n| 186.|[How do you get meta data of a module?](#q-how-do-you-get-meta-data-of-a-module)|\n| 187.|[What is a comma operator?](#q-what-is-a-comma-operator)|\n| 188.|[What is the advantage of a comma operator?](#q-what-is-the-advantage-of-a-comma-operator)|\n| 189.|[Explain event delegation?](#q-explain-event-delegation)|\n| 190.|[Explain how prototypal inheritance works?](#q-explain-how-prototypal-inheritance-works)|\n| 191.|[Example of Prototypal Inheritance?](#q-example-of-prototypal-inheritance)|\n| 192.|[What do you think of AMD vs CommonJS?](#q-what-do-you-think-of-amd-vs-commonjs)|\n| 193.|[Explain why the following does not work as an IIFE: `function foo(){ }();`. What needs to be changed to properly make it an IIFE?](#q-explain-why-the-following-does-not-work-as-an-iife-function-foo-what-needs-to-be-changed-to-properly-make-it-an-iife)|\n| 194.|[What is the difference between a variable that is: `null`, `undefined` or undeclared? How would you go about checking for any of these states?](#q-what-is-the-difference-between-a-variable-that-is-null-undefined-or-undeclared-how-would-you-go-about-checking-for-any-of-these-states)|\n| 195.|[Can you describe the main difference between a `.forEach` loop and a `.map()` loop and why you would pick one versus the other?](#q-can-you-describe-the-main-difference-between-a-foreach-loop-and-a-map-loop-and-why-you-would-pick-one-versus-the-other)|\n| 196.|[What is a typical use case for anonymous functions?](#q-what-is-a-typical-use-case-for-anonymous-functions)|\n| 197.|[How do you organize your code? (module pattern, classical inheritance?)](#q-how-do-you-organize-your-code-module-pattern-classical-inheritance)|\n| 198.|[What is the difference between host objects and native objects?](#q-what-is-the-difference-between-host-objects-and-native-objects)|\n| 199.|[Difference between: `function Person(){}`, `var person = Person()`, and `var person = new Person()`?](#q-difference-between-function-person-var-person-person-and-var-person-new-person)|\n| 200.|[What is the difference between `.call` and `.apply`?](#q-what-is-the-difference-between-call-and-apply)|\n| 201.|[Explain `Function.prototype.bind`?](#q-explain-functionprototypebind)|\n| 202.|[When would you use `document.write()`?](#q-when-would-you-use-documentwrite)|\n| 203.|[What is the difference between feature detection, feature inference, and using the UA string?](#q-what-is-the-difference-between-feature-detection-feature-inference-and-using-the-ua-string)|\n| 204.|[Explain Ajax in detail?](#q-explain-ajax-in-detail)|\n| 205.|[Explain how JSONP works (and how It is not really Ajax)](#q-explain-how-jsonp-works-and-how-it-s-not-really-ajax)|\n| 206.|[What is the difference between an \"attribute\" and a \"property\"?](#q-what-is-the-difference-between-an-attribute-and-a-property)|\n| 207.|[Why is extending built-in JavaScript objects not a good idea?](#q-why-is-extending-built-in-javascript-objects-not-a-good-idea)|\n| 208.|[Difference between document `load` event and document `DOMContentLoaded` event?](#q-difference-between-document-load-event-and-document-domcontentloaded-event)|\n| 209.|[What is the difference between `==` and `===`?](#q-what-is-the-difference-between-and)|\n| 210.|[Explain the same-origin policy with regards to JavaScript?](#q-explain-the-same-origin-policy-with-regards-to-javascript)|\n| 211.|[Why is it called a Ternary expression, what does the word \"Ternary\" indicate?](#q-why-is-it-called-a-ternary-expression-what-does-the-word-ternary-indicate)|\n| 212.|[What is `\"use strict\";`? What are the advantages and disadvantages to using it?](#q-what-is-use-strict-what-are-the-advantages-and-disadvantages-to-using-it)|\n| 213.|[Why is it, in general, a good idea to leave the global scope of a website as-is and never touch it?](#q-why-is-it-in-general-a-good-idea-to-leave-the-global-scope-of-a-website-as-is-and-never-touch-it)|\n| 214.|[Why would you use something like the `load` event? Does this event have disadvantages? Do you know any alternatives, and why would you use those?](#q-why-would-you-use-something-like-the-load-event-does-this-event-have-disadvantages-do-you-know-any-alternatives-and-why-would-you-use-those)|\n| 215.|[What is the extent of your experience with Promises and/or their polyfills?](#q-what-is-the-extent-of-your-experience-with-promises-and-or-their-polyfills)|\n| 216.|[What are the pros and cons of using Promises instead of callbacks?](#q-what-are-the-pros-and-cons-of-using-promises-instead-of-callbacks)|\n| 217.|[What are some of the advantages/disadvantages of writing JavaScript code in a language that compiles to JavaScript?](#q-what-are-some-of-the-advantages-disadvantages-of-writing-javascript-code-in-a-language-that-compiles-to-javascript)|\n| 218.|[What tools and techniues do you use for debugging JavaScript code?](#q-what-tools-and-techniues-do-you-use-for-debugging-javascript-code)|\n| 219.|[What language constructions do you use for iterating over object properties and array items?](#q-what-language-constructions-do-you-use-for-iterating-over-object-properties-and-array-items)|\n| 220.|[Explain the difference between mutable and immutable objects?](#q-explain-the-difference-between-mutable-and-immutable-objects)|\n| 221.|[What is an example of an immutable object in JavaScript?](#q-what-is-an-example-of-an-immutable-object-in-javascript)|\n| 222.|[How can you achieve immutability in your own code?](#q-how-can-you-achieve-immutability-in-your-own-code)|\n| 223.|[Explain the difference between synchronous and asynchronous functions?](#q-explain-the-difference-between-synchronous-and-asynchronous-functions)|\n| 224.|[What is event loop? What is the difference between call stack and task ueue?](#q-what-is-event-loop-what-is-the-difference-between-call-stack-and-task-ueue)|\n| 225.|[Explain the differences on the usage of `foo` between `function foo() {}` and `var foo = function() {}`?](#q-explain-the-differences-on-the-usage-of-foo-between-function-foo-and-var-foo-function)|\n| 226.|[What are the differences between variables created using `let`, `var` or `const`?](#q-what-are-the-differences-between-variables-created-using-let-var-or-const)|\n| 227.|[What is the definition of a higher-order function?](#q-what-is-the-definition-of-a-higher-order-function)|\n| 228.|[Can you give an example of a curry function and why this syntax offers an advantage?](#q-can-you-give-an-example-of-a-curry-function-and-why-this-syntax-offers-an-advantage)|\n| 229.|[How can you share code between files?](#q-how-can-you-share-code-between-files)|\n| 230.|[Why you might want to create static class members?](#q-why-you-might-want-to-create-static-class-members)|\n| 231.|[What is the difference between `undefined` and `not defined` in JavaScript?](#q-what-is-the-difference-between-undefined-and-not-defined-in-javascript)|\n| 232.|[For which value of `x` the results of the following statements are not the same?](#q-for-which-value-of-x-the-results-of-the-following-statements-are-not-the-same)|\n| 233.|[What is the drawback of declaring methods directly in JavaScript objects?](#q-what-is-the-drawback-of-declaring-methods-directly-in-javascript-objects)|\n| 234.|[What is “closure” in javascript? Can you provide an example?](#q-what-is-closure-in-javascript-can-you-provide-an-example)|\n| 235.|[Write a mul function which will work properly when invoked with following syntax?](#q-write-a-mul-function-which-will-work-properly-when-invoked-with-following-syntax)|\n| 236.|[How to empty an array in JavaScript?](#q-how-to-empty-an-array-in-javascript)|\n| 237.|[How to check if an object is an array or not?](#q-how-to-check-if-an-object-is-an-array-or-not)|\n| 238.|[What is `undefined x 1` in JavaScript?](#q-what-is-undefined-x-1-in-javascript)|\n| 239.|[What is the difference between declaring a function in the formats listed below?](#q-what-is-the-difference-between-declaring-a-function-in-the-formats-listed-below)|\n| 240.|[In which case the function definition is not hoisted in JavaScript?](#q-in-which-case-the-function-definition-is-not-hoisted-in-javascript)|\n| 241.|[What’s the difference between `typeof` and `instanceof`?](#q-what-s-the-difference-between-typeof-and-instanceof)|\n| 242.|[Calculate the length of the associative array?](#q-calculate-the-length-of-the-associative-array)|\n| 243.|[Difference between `Function`, `Method` and `Constructor` calls in JavaScript?](#q-difference-between-function-method-and-constructor-calls-in-javascript)|\n| 244.|[What are Service Workers and when can you use them?](#q-what-are-service-workers-and-when-can-you-use-them)|\n| 245.|[What is the difference between a method and a function in javascript?](#q-what-is-the-difference-between-a-method-and-a-function-in-javascript)|\n| 246.|[What is IIFE (Immediately Invoked Function Expression) and how it can be useful?](#q-what-is-iife-immediately-invoked-function-expression-and-how-it-can-be-useful)|\n| 247.|[Describe Singleton Pattern In JavaScript?](#q-describe-singleton-pattern-in-javascript)|\n| 248.|[Singleton Design Pattern Implementation?](#q-singleton-design-pattern-implementation)|\n| 249.|[Write a function called deepClone which takes an object and creates a object copy of it?](#q-write-a-function-called-deepclone-which-takes-an-object-and-creates-a-object-copy-of-it)|\n| 250.|[Best way to detect `undefined` object property in JavaScript?](#q-best-way-to-detect-undefined-object-property-in-javascript)|\n| 251.|[Write a function called `Clone` which takes an object and creates a object copy of it but not copy deep property of object?](#q-write-a-function-called-clone-which-takes-an-object-and-creates-a-object-copy-of-it-but-not-copy-deep-property-of-object)|\n| 252.|[What are promises and how they are useful?](#q-what-are-promises-and-how-they-are-useful)|\n| 253.|[How to check whether a key exist in a JavaScript object or not?](#q-how-to-check-whether-a-key-exist-in-a-javascript-object-or-not)|\n| 254.|[What is NaN, why do we need it, and when can it break the page?](#q-what-is-nan-why-do-we-need-it-and-when-can-it-break-the-page)|\n| 255.|[How to check if the value of a variable in an array?](#q-how-to-check-if-the-value-of-a-variable-in-an-array)|\n| 256.|[Best way to detect reference values of any type in JavaScript?](#q-best-way-to-detect-reference-values-of-any-type-in-javascript)|\n| 257.|[How does Object.create method works JavaScript?](#q-how-does-objectcreate-method-works-javascript)|\n| 258.|[How to use constructor functions for inheritance in JavaScript?](#q-how-to-use-constructor-functions-for-inheritance-in-javascript)|\n| 259.|[How we can prevent modification of object in JavaScript?](#q-how-we-can-prevent-modification-of-object-in-javascript)|\n| 260.|[Write a log function which will add prefix `(your message)` to every message you log using console.log ?](#q-write-a-log-function-which-will-add-prefix-your-message-to-every-message-you-log-using-consolelog)|\n| 261.|[Write a function which will test string as a literal and as an object ?](#q-write-a-function-which-will-test-string-as-a-literal-and-as-an-object)|\n| 262.|[What is typical use case for anonymous function in JavaScript?](#q-what-is-typical-use-case-for-anonymous-function-in-javascript)|\n| 263.|[How to set a default parameter value?](#q-how-to-set-a-default-parameter-value)|\n| 264.|[Write code for merge two JavaScript Object dynamically?](#q-write-code-for-merge-two-javascript-object-dynamically)|\n| 265.|[What is non-enumerable property in JavaScript and how you can create one?](#q-what-is-non-enumerable-property-in-javascript-and-how-you-can-create-one)|\n| 266.|[What is Function binding ?](#q-what-is-function-binding)|\n| 267.|[Explain event delegation?](#q-explain-event-delegation)|\n| 268.|[Explain how `this` works in JavaScript?](#q-explain-how-this-works-in-javascript)|\n| 269.|[Explain how prototypal inheritance works?](#q-explain-how-prototypal-inheritance-works)|\n| 270.|[What do you think of AMD vs CommonJS?](#q-what-do-you-think-of-amd-vs-commonjs)|\n| 274.|[Can you describe the main difference between a `.forEach` loop and a `.map()` loop and why you would pick one versus the other?](#q-can-you-describe-the-main-difference-between-a-foreach-loop-and-a-map-loop-and-why-you-would-pick-one-versus-the-other)|\n| 283.|[Have you ever used JavaScript templating? If so, what libraries have you used?](#q-have-you-ever-used-javascript-templating-if-so-what-libraries-have-you-used)|\n| 285.|[What is the difference between an \"attribute\" and a \"property\"?](#q-what-is-the-difference-between-an-attribute-and-a-property)|\n| 287.|[Difference between document `load` event and document `DOMContentLoaded` event?](#q-difference-between-document-load-event-and-document-domcontentloaded-event)\n| 289.|[What is JSON and its common operations?](#q-what-is-json-and-its-common-operations)|\n| 290.|[What is the purpose of array slice method?](#q-what-is-the-purpose-of-array-slice-method)|\n| 291.|[What is the purpose of array splice method?](#q-what-is-the-purpose-of-array-splice-method)|\n| 292.|[What is the difference between slice and splice?](#q-what-is-the-difference-between-slice-and-splice)|\n| 293.|[How do you compare Object and Map?](#q-how-do-you-compare-object-and-map)|\n| 294.|[How do you redeclare variables in switch block without an error?](#q-how-do-you-redeclare-variables-in-switch-block-without-an-error)|\n| 295.|[How to create and trigger events in javascript?](#q-how-to-create-and-trigger-events-in-javascript)|\n| 296.|[What is difference between window.frames window.parent and window.top in JavaScript?](#q-what-is-difference-between-windowframes-windowparent-and-windowtop-in-javascript)|\n| 297.|[In JavaScript, what is the difference between var x = 1 and x = 1?](#q-in-javascript-what-is-the-difference-between-var-x-1-and-x-1)|\n| 298.|[What is Associative Array? How do we use it?](#q-what-is-associative-array-how-do-we-use-it)|\n| 299.|[What is difference between Classic Inheritance and Prototypical Inheritance?](#q-what-is-difference-between-classic-inheritance-and-prototypical-inheritance)|\n| 300.|[What is difference between private variable, public variable and static variable? How we achieve this in JS?](#q-what-is-difference-between-private-variable-public-variable-and-static-variable-how-we-achieve-this-in-js)|\n| 301.|[How to add and remove properties to object in runtime?](#q-how-to-add-and-remove-properties-to-object-in-runtime)|\n| 302.|[How to extend built-in objects?](#q-how-to-extend-built-in-objects)|\n| 303.|[Why extending array is bad idea?](#q-why-extending-array-is-bad-idea)|\n| 304.|[What is difference between browser detection and feature detection?](#q-what-is-difference-between-browser-detection-and-feature-detection)|\n| 305.|[What is difference between Graceful Degradation and Progressive Enhancement?](#q-what-is-difference-between-graceful-degradation-and-progressive-enhancement)|\n| 306.|[In JavaScript, why is the “this” operator inconsistent?](#q-in-javascript-why-is-the-this-operator-inconsistent)|\n| 307.|[What unit testing framework do you use? and why?](#q-what-unit-testing-framework-do-you-use-and-why)|\n| 308.|[Explain the difference between Object.freeze() vs const?](#q-explain-the-difference-between-objectfreeze-vs-const)|\n| 309.|[What is generator in JS?](#q-what-is-generator-in-js)|\n| 310.|[Describe the Revealing Module Pattern in javascript?](#q-describe-the-revealing-module-pattern-in-javascript)|\n| 311.|[Compare Async-Await and Generators usage to achive same functionality?](#q-compare-async-await-and-generators-usage-to-achive-same-functionality)|\n| 312.|[Explain escape() and unescape() functions?](#q-explain-escape-and-unescape-functions)|\n| 313.|[What do you understand by Screen objects?](#q-what-do-you-understand-by-screen-objects)|\n| 314.|[How will you remove duplicates from an array in JavaScript?](#q-how-will-you-remove-duplicates-from-an-array-in-javascript)|\n| 315.|[Explain NEGATIVE_INFINITY in JavaScript?](#q-explain-negative-infinity-in-javascript)|\n| 316.|[What do you understand by ViewState and SessionState?](#q-what-do-you-understand-by-viewstate-and-sessionstate)|\n| 317.|[Explain var self = this in JavaScript?](#q-explain-var-self-this-in-javascript)|\n| 318.|[What is difference between append() vs appendChild()?](#q-what-is-difference-between-append-vs-appendchild)|\n| 319.|[What is difference between null vs undefined?](#q-what-is-difference-between-null-vs-undefined)|\n| 320.|[What is difference between array[] vs object()?](#q-what-is-difference-between-array-vs-object)|\n| 321.|[What is difference between async() or defer() keyword in JavaScript?](#q-what-is-difference-between-async-or-defer-keyword-in-javascript)|\n| 322.|[What is difference between async() and await() in ajax?](#q-what-is-difference-between-async-and-await-in-ajax)|\n| 323.|[What is reuest header in javascript?](#q-what-is-reuest-header-in-javascript)|\n| 324.|[What is rendering in JavaScript?](#q-what-is-rendering-in-javascript)|\n| 325.|[Define the various types of errors which occur in JavaScript programming language?](#q-define-the-various-types-of-errors-which-occur-in-javascript-programming-language)|\n| 326.|[What is unshift() method in JavaScript?](#q-what-is-unshift-method-in-javascript)|\n| 327.|[What is the difference between HTMLCollection and NodeList?](#q-what-is-the-difference-between-htmlcollection-and-nodelist)|\n| 328.|[What is the difference between firstChild and firstElementChild?](#q-what-is-the-difference-between-firstchild-and-firstelementchild)|\n| 329.|[Name the two functions that are used to create an HTML element dynamically?](#q-name-the-two-functions-that-are-used-to-create-an-html-element-dynamically)|\n| 330.|[What is callback() function in javascript?](#q-what-is-callback-function-in-javascript)|\n| 331.|[What is shallow copy and deep copy in javascript?](#q-what-is-shallow-copy-and-deep-copy-in-javascript)|\n| 332.|[What is difference between stoppropagation vs stopimmediatepropagation vs preventdefault in javascript?](#q-what-is-difference-between-stoppropagation-vs-stopimmediatepropagation-vs-preventdefault-in-javascript)|\n| 333.|[Explain array methods [ join(), pop(), push(), shift(), unshift(), concat(), map(), filter(), reduce(), reduceRight(), every(), some(), indexOf(), lastIndexOf(), find(), findIndex(), includes() ]](#q-explain-array-methods-join-pop-push-shift-unshift-concat-map-filter-reduce-reduceright-every-some-indexof-lastindexof-find-findindex-includes)|\n| 334.|[When to use function declarations and expressions in JavaScript?](#q-when-to-use-function-declarations-and-expressions-in-javascript)|\n| 335.|[How to avoid callback hell in javascript?](#q-how-to-avoid-callback-hell-in-javascript)|\n| 336.|[Why is eval() considered evil and dangerous?](#q-why-is-eval-considered-evil-and-dangerous)|\n| 337.|[What is the difference between encryption and hashing?](#q-what-is-the-difference-between-encryption-and-hashing)|\n| 338.|[What is Proxies and Reflection in JavaScript?](#q-what-is-proxies-and-reflection-in-javascript)|\n| 339.|[How do you check whether an object can be extendable or not?](#q-how-do-you-check-whether-an-object-can-be-extendable-or-not)|\n| 340.|[What are the different ways to make an object non-extensible?](#q-what-are-the-different-ways-to-make-an-object-non-extensible)|\n| 341.|[Is enums feature available in javascript?](#q-is-enums-feature-available-in-javascript)|\n| 342.|[How do I modify the url without reloading the page?](#q-how-do-i-modify-the-url-without-reloading-the-page)|\n| 343.|[What is throttling and debouncing in javascript?](#q-what-is-throttling-and-debouncing-in-javascript)|\n| 344.|[How to validate JSON Object in javascript?](#q-how-to-validate-json-object-in-javascript)|\n| 345.|[How to check if page is fully loaded using javascript?](#q-how-to-check-if-page-is-fully-loaded-using-javascript)|\n| 346.|[Explain browser console logs features?](#q-explain-browser-console-logs-features)|\n| 347.|[What are the difference between console.log() and console.dir()?](#q-what-are-the-difference-between-consolelog-and-consoledir)|\n| 348.|[How to Copy Text to Clipboard?](#q-how-to-copy-text-to-clipboard)|\n| 349.|[Explain types of Memory Leaks in JavaScript?](#q-explain-types-of-memory-leaks-in-javascript)|\n| 350.|[How accidental closures might cause memory leaks in IE?](#q-how-accidental-closures-might-cause-memory-leaks-in-ie)|\n| 351.|[How to convert Decimal to Binary in JavaScript?](#q-how-to-convert-decimal-to-binary-in-javascript)|\n\n\u003cbr/\u003e\n\n## Q. ***What is difference between document.getElementById() and document.querySelector()?***\n\n* **document.getElementById()**\n\nReturns an element object representing the element whose id property matches the specified string. Since element IDs are required to be unique if specified, they're a useful way to get access to a specific element quickly.\n\n```javascript\nelement = document.getElementById(id);\n```\n\n* **document.querySelector()**\n\nReturns the first matching Element node within the node\\'s subtree. If no matching node is found, null is returned.\n\n```javascript\nelement = document.querySelector(selectors);\n```\n\n* **document.querySelectorAll()**\n\nReturns a NodeList containing all matching Element nodes within the node\\'s subtree, or an empty NodeList if no matches are found.\n\n```javascript\nelement = document.querySelectorAll(selectors);\n```\n\n*Note: `querySelector()` is more useful when we want to use more complex selectors*.\n\n\u003cdiv align=\"right\"\u003e\n    \u003cb\u003e\u003ca href=\"#\"\u003e↥ back to top\u003c/a\u003e\u003c/b\u003e\n\u003c/div\u003e\n\n## Q. ***When to use reduce(), map(), foreach() and filter() in JavaScript?***\n\n* **forEach()**  \n\nIt takes a callback function and run that callback function on each element of array one by one.\n\nBasically forEach works as a traditional for loop looping over the array and providing array elements to do operations on them.\n\n```javascript\nvar arr = [10, 20, 30];\n\narr.forEach(function (elem, index){\n   console.log(elem + ' comes at ' + index);\n})\n```\nOutput\n```\n10 comes at 0\n20 comes at 1\n30 comes at 2\n```\n\n* **filter()** \n\nThe main difference between forEach() and filter() is that forEach just loop over the array and executes the callback but filter executes the callback and check its return value. If the value is true element remains in the resulting array but if the return value is false the element will be removed for the resulting array.\n\n*Note: filter does not update the existing array it will return a new filtered array every time*.\n\n```javascript\nvar arr = [10, 20, 30]; \n\nvar result = arr.filter(function(elem){\n    return elem !== 20;\n})\nconsole.log(result)\n```\nOutput\n```\n[10, 30]\n```\n\n* **map()**\n\nmap() like filter() \u0026 forEach() takes a callback and run it against every element on the array but whats makes it unique is it generate a new array based on your existing array.\n\nLike filter(), map() also returns an array. The provided callback to map modifies the array elements and save them into the new array upon completion that array get returned as the mapped array.\n\n```javascript\nvar arr = [10, 20, 30];\n\nvar mapped = arr.map(function(elem) {\n    return elem * 10;\n});\nconsole.log(mapped)\n```\nOutput\n```\n[100, 200, 300]\n```\n\n* **reduce()** \n\nreduce() method of the array object is used to reduce the array to one single value.\n\n```javascript\nvar arr = [10, 20, 30];\n\nvar sum = arr.reduce(function(sum, elem) {\n    return sum + elem;\n});\nconsole.log(sum); // Output: 60\n```\n\n\u003cdiv align=\"right\"\u003e\n    \u003cb\u003e\u003ca href=\"#\"\u003e↥ back to top\u003c/a\u003e\u003c/b\u003e\n\u003c/div\u003e\n\n## Q. ***What is Hoisting in JavaScript?***\n\nHoisting is a JavaScript mechanism where variables and function declarations are moved to the top of their scope before code execution.\n\n**Example 01:** Variable Hoisting  \n\n```javascript\nconsole.log(message); // output : undefined\nvar message = \"The variable Has been hoisted\";\n```\nThe above code looks like as below to the interpreter,\n\n```javascript\nvar message;\nconsole.log(message);\nmessage = \"The variable Has been hoisted\";\n```\n**Example 02:** Function Hoisting\n\n```javascript\nfunction hoist() {\n  a = 20;\n  var b = 100;\n}\n\nhoist();\n\nconsole.log(a);\n/* \nAccessible as a global variable outside hoist() function\nOutput: 20\n*/\n\nconsole.log(b);\n/*\nSince it was declared, it is confined to the hoist() function scope.\nWe can't print it out outside the confines of the hoist() function.\nOutput: ReferenceError: b is not defined\n*/\n```\n\nAll declarations (function, var, let, const and class) are hoisted in JavaScript, while the `var` declarations are initialized with `undefined`, but `let` and `const` declarations remain uninitialized.\n\n```javascript\nconsole.log(a);\nlet a = 3;\n\n// Output: ReferenceError: a is not defined\n```\nThey will only get initialized when their lexical binding (assignment) is evaluated during runtime by the JavaScript engine. This means we can’t access the variable before the engine evaluates its value at the place it was declared in the source code. This is what we call **Temporal Dead Zone**, A time span between variable creation and its initialization where they can’t be accessed.\n\n*Note: JavaScript only hoists declarations, not initialisation*\n\n\u003cdiv align=\"right\"\u003e\n    \u003cb\u003e\u003ca href=\"#\"\u003e↥ back to top\u003c/a\u003e\u003c/b\u003e\n\u003c/div\u003e\n\n## Q. ***What are closures?***\n\nA closure is the combination of a function and the lexical environment within which that function was declared. i.e, It is an inner function that has access to the outer or enclosing function’s variables. The closure has three scope chains\n\n* Own scope where variables defined between its curly brackets\n* Outer function’s variables\n* Global variables\n\n```javascript\nfunction Welcome(name) {\n  var greetingInfo = function(message) {\n    console.log(message+' '+name);\n  }\n  return greetingInfo;\n}\nvar myFunction = Welcome('John');\nmyFunction('Welcome '); // Output: Welcome John\nmyFunction('Hello Mr.'); // output: Hello Mr.John\n```\n\nAs per the above code, the inner `function greetingInfo()` has access to the variables in the outer `function Welcome()` even after outer function has returned.\n\n\u003cdiv align=\"right\"\u003e\n    \u003cb\u003e\u003ca href=\"#\"\u003e↥ back to top\u003c/a\u003e\u003c/b\u003e\n\u003c/div\u003e\n\n## Q. ***How do you clone an object in JavaScript?***\n\nUsing the object spread operator `...`, the object own enumerable properties can be copied into the new object. This creates a shallow clone of the object.\n\n```javascript\nconst obj = { a: 1, b: 2 }\nconst shallowClone = { ...obj }\n```\n\nWith this technique, prototypes are ignored. In addition, nested objects are not cloned, but rather their references get copied, so nested objects still refer to the same objects as the original. Deep-cloning is much more complex in order to effectively clone any type of object (Date, RegExp, Function, Set, etc) that may be nested within the object.\n\nOther alternatives include:\n\n* **JSON.parse(JSON.stringify(obj))** can be used to deep-clone a simple object, but it is CPU-intensive and only accepts valid JSON (therefore it strips functions and does not allow circular references).\n* **Object.assign({}, obj)** is another alternative.\n* **Object.keys(obj).reduce((acc, key) =\u003e (acc[key] = obj[key], acc), {})** is another more verbose alternative that shows the concept in greater depth.\n\n\u003cdiv align=\"right\"\u003e\n    \u003cb\u003e\u003ca href=\"#\"\u003e↥ back to top\u003c/a\u003e\u003c/b\u003e\n\u003c/div\u003e\n\n## Q. ***What are the possible ways to create objects in JavaScript?***\n\n**a.) Object constructor**: The simpliest way to create an empty object is using Object constructor. Currently this approach is not recommended.\n\n```javascript\n var object = new Object();\n```\n\n**b.) Object create method**: The create method of Object creates a new object by passing the prototype object as a parameter\n\n```javascript\n var object = Object.create(null);\n```\n\n**c.) Object literal syntax**: The object literal syntax is equivalent to create method when it passes null as parameter\n\n```javascript\n var object = {};\n```\n\n**d.) Function constructor**: Create any function and apply the new operator to create object instances,\n\n```javascript\n function Person(name) {\n  var object = {};\n  object.name = name;\n  object.age = 26;\n  return object;\n }\n var object = new Person(\"Alex\");\n```\n\n**e.) Function constructor with prototype**: This is similar to function constructor but it uses prototype for their properties and methods,\n\n```javascript\nfunction Person(){}\nPerson.prototype.name = \"Alex\";\nvar object = new Person();\n```\n\nThis is equivalent to an instance created with an object create method with a function prototype and then call that function with an instance and parameters as arguments.\n\n```javascript\nfunction func {};\n\nnew func(x, y, z);\n\n// **(OR)**\n\n// Create a new instance using function prototype.\nvar newInstance = Object.create(func.prototype)\n\n// Call the function\nvar result = func.call(newInstance, x, y, z),\n\n// If the result is a non-null object then use it otherwise just use the new instance.\nconsole.log(result \u0026\u0026 typeof result === 'object' ? result : newInstance);\n```\n\n**f.) ES6 Class syntax**: ES6 introduces class feature to create the objects\n\n```javascript\nclass Person {\n constructor(name) {\n    this.name = name;\n }\n}\n\nvar object = new Person(\"Alex\");\n```\n\n**g.) Singleton pattern**: A Singleton is an object which can only be instantiated one time. Repeated calls to its constructor return the same instance and this way one can ensure that they don't accidentally create multiple instances.\n\n```javascript\nvar object = new function() {\n  this.name = \"Alex\";\n}\n```\n\n\u003cdiv align=\"right\"\u003e\n    \u003cb\u003e\u003ca href=\"#\"\u003e↥ back to top\u003c/a\u003e\u003c/b\u003e\n\u003c/div\u003e\n\n## Q. ***What are the javascript data types?***\n\nBelow are the list of javascript data types available\n1. Number\n2. String\n3. Boolean\n4. Object\n5. Undefined\n\n\u003cdiv align=\"right\"\u003e\n    \u003cb\u003e\u003ca href=\"#\"\u003e↥ back to top\u003c/a\u003e\u003c/b\u003e\n\u003c/div\u003e\n\n## Q. ***What are global variables?***\n\nGlobal 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\n\n```javascript\nmsg = \"Hello\" // var is missing, it becomes global variable\n```\n\nThe problem with global variables is the conflict of variable names of local and global scope. It is also difficult to debug and test the code that relies on global variables.\n\n\u003cdiv align=\"right\"\u003e\n    \u003cb\u003e\u003ca href=\"#\"\u003e↥ back to top\u003c/a\u003e\u003c/b\u003e\n\u003c/div\u003e\n\n## Q. ***What is variable shadowing in javascript?***\n\nVariable shadowing occurs when a variable declared within a certain scope (decision block, method, or inner class) has the same name as a variable declared in an outer scope. This outer variable is said to be shadowed.\n\nIf there is a variable in the global scope, and you'd like to create a variable with the same name in a function. The variable in the inner scope will temporarily shadow the variable in the outer scope.\n\n```javascript\nvar val = 10;\n\nfunction Hoist(val) {\n    alert(val);\n}\n\nHoist(20);\n```\n\nOutput\n```\n20\n```\n\n\u003cdiv align=\"right\"\u003e\n    \u003cb\u003e\u003ca href=\"#\"\u003e↥ back to top\u003c/a\u003e\u003c/b\u003e\n\u003c/div\u003e\n\n## Q. ***What is an event flow?***\n\nEvent flow is the order in which event is received on the web page. When you click an element that is nested in various other elements, before your click actually reaches its destination, or target element, it must trigger the click event each of its parent elements first, starting at the top with the global window object.\n\nThere are two ways of event flow\n* Top to Bottom(Event Capturing)\n* Bottom to Top (Event Bubbling)\n\n\u003cdiv align=\"right\"\u003e\n    \u003cb\u003e\u003ca href=\"#\"\u003e↥ back to top\u003c/a\u003e\u003c/b\u003e\n\u003c/div\u003e\n\n## Q. ***What is event bubbling?***\n\nEvent bubbling is a type of event propagation where the event first triggers on the innermost target element, and then successively triggers on the ancestors (parents) of the target element in the same nesting hierarchy till it reaches the outermost DOM element.\n\nExample: If you click on EM, the handler on DIV runs.  \n\n```html\n\u003cdiv onclick=\"alert('The handler!')\"\u003e\n  \u003cem\u003eIf you click on \u003ccode\u003eEM\u003c/code\u003e, the handler on \u003ccode\u003eDIV\u003c/code\u003e runs.\u003c/em\u003e\n\u003c/div\u003e\n```\n\n* **Stopping bubbling**  \n\n```html\n\n\u003cbody onclick=\"alert(`the bubbling doesn\\'t reach here`)\"\u003e\n  \u003cbutton onclick=\"event.stopPropagation()\"\u003eClick me\u003c/button\u003e\n\u003c/body\u003e\n```\n\n\u003cdiv align=\"right\"\u003e\n    \u003cb\u003e\u003ca href=\"#\"\u003e↥ back to top\u003c/a\u003e\u003c/b\u003e\n\u003c/div\u003e\n\n## Q. ***What is event capturing?***\n\nEvent capturing is a type of event propagation where the event is first captured by the outermost element and then successively triggers on the descendants (children) of the target element in the same nesting hierarchy till it reaches the inner DOM element.\n\n\u003cdiv align=\"right\"\u003e\n    \u003cb\u003e\u003ca href=\"#\"\u003e↥ back to top\u003c/a\u003e\u003c/b\u003e\n\u003c/div\u003e\n\n## Q. ***What is prototype chain?***\n\nNearly all objects in JavaScript are instances of **Object**. That means all the objects in JavaScript inherit the properties and methods from **Object.prototype**. This is called **Prototype chaining**.\n\n**Prototype chaining** is used to build new types of objects based on existing ones. It is similar to inheritance in a class based language. The prototype on object instance is available through `Object.getPrototypeOf(object)` or `__proto__` property whereas prototype on constructors function is available through **Object.prototype**.\n\n```javascript\nfunction Person(firstName, lastName, age) {\n  this.firstName = firstName;\n  this.lastName = lastName;\n  this.age = age;\n}\n//Person class created\nPerson.prototype.getFullName = function() {\n  return this.firstName + \" \" + this.lastName;\n}\n\n// we have added getFullName method in Person’s prototype.\nvar person = new Person(\"John\", \"K\", 25);\n// It will create an instance of the Person class\n\u003e person.hasOwnProperty(\"firstName\");  // true\n\u003e person.hasOwnProperty(\"getFullName\");  // false\n\u003e person.getFullName(); // John K\n```\n\n\u003cdiv align=\"right\"\u003e\n    \u003cb\u003e\u003ca href=\"#\"\u003e↥ back to top\u003c/a\u003e\u003c/b\u003e\n\u003c/div\u003e\n\n## Q. ***What is the difference between Call, Apply and Bind?***\n\n**a.) call()**\n\nThe call() method invokes a function with a given `this` value and arguments provided one by one\n\n```javascript\nvar employee1 = {firstName: 'John', lastName: 'Rodson'};\nvar employee2 = {firstName: 'Jimmy', lastName: 'Baily'};\n\nfunction invite(greeting1, greeting2) {\n    console.log(greeting1 + ' ' + this.firstName + ' ' + this.lastName+ ', '+ greeting2);\n}\n\ninvite.call(employee1, 'Hello', 'How are you?'); // Hello John Rodson, How are you?\ninvite.call(employee2, 'Hello', 'How are you?'); // Hello Jimmy Baily, How are you?\n```\n**b.) apply()** \n\nInvokes the function and allows you to pass in arguments as an array\n\n```javascript\nvar employee1 = {firstName: 'John', lastName: 'Rodson'};\nvar employee2 = {firstName: 'Jimmy', lastName: 'Baily'};\n\nfunction invite(greeting1, greeting2) {\n    console.log(greeting1 + ' ' + this.firstName + ' ' + this.lastName+ ', '+ greeting2);\n}\n\ninvite.apply(employee1, ['Hello', 'How are you?']); // Hello John Rodson, How are you?\ninvite.apply(employee2, ['Hello', 'How are you?']); // Hello Jimmy Baily, How are you?\n```\n\n**c.) bind()**\n\nreturns a new function, allowing you to pass in an array and any number of arguments\n\n```javascript\nvar employee1 = {firstName: 'John', lastName: 'Rodson'};\nvar employee2 = {firstName: 'Jimmy', lastName: 'Baily'};\n\nfunction invite(greeting1, greeting2) {\n    console.log(greeting1 + ' ' + this.firstName + ' ' + this.lastName+ ', '+ greeting2);\n}\n\nvar inviteEmployee1 = invite.bind(employee1);\nvar inviteEmployee2 = invite.bind(employee2);\ninviteEmployee1('Hello', 'How are you?'); // Hello John Rodson, How are you?\ninviteEmployee2('Hello', 'How are you?'); // Hello Jimmy Baily, How are you?\n```\n\n\u003cdiv align=\"right\"\u003e\n    \u003cb\u003e\u003ca href=\"#\"\u003e↥ back to top\u003c/a\u003e\u003c/b\u003e\n\u003c/div\u003e\n\n## Q. ***What is the difference between == and === operators?***\n\nJavaScript provides both strict(===, !==) and type-converting(==, !=) equality comparison. The strict operators takes 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,\n1. Two strings are strictly equal when they have the same sequence of characters, same length, and same characters in corresponding positions.\n2. Two numbers are strictly equal when they are numerically equal. i.e, Having the same number value.\n   There are two special cases in this,\n   1. NaN is not equal to anything, including NaN.\n   2. Positive and negative zeros are equal to one another.\n3. Two Boolean operands are strictly equal if both are true or both are false.\n4. Two objects are strictly equal if they refer to the same Object.\n5. Null and Undefined types are not equal with ===, but equal with ==. i.e,\n    null===undefined --\u003e false but null==undefined --\u003e true\n\n**Examples**\n\n```javascript\n0 == false   // true\n0 === false  // false\n1 == \"1\"     // true\n1 === \"1\"    // false\nnull == undefined // true\nnull === undefined // false\n'0' == false // true\n'0' === false // false\n[]==[] or []===[] //false, refer different objects in memory\n{}=={} or {}==={} //false, refer different objects in memory\n```\n\n\u003cdiv align=\"right\"\u003e\n    \u003cb\u003e\u003ca href=\"#\"\u003e↥ back to top\u003c/a\u003e\u003c/b\u003e\n\u003c/div\u003e\n\n## Q. ***What is a first class function?***\n\nJavaScript functions are first-class functions meaning functions and objects are treated as the same thing. Functions can be stored as a variable inside an object or an array as well as it can be passed as an argument or be returned by another function. That makes function \"first-class citizens in JavaScript\"\n\n**Example:** Assign a function to a variable\n\n```javascript\nconst message = function() {\n   console.log(\"Hello World!\");\n}\n\nmessage(); // Invoke it using the variable\n```\n\n**Example:** Pass a function as an Argument\n\n```javascript\nfunction sayHello() {\n   return \"Hello, \";\n}\nfunction greeting(helloMessage, name) {\n  console.log(helloMessage() + name);\n}\n// Pass `sayHello` as an argument to `greeting` function\ngreeting(sayHello, \"JavaScript!\");\n```\n\n**Example:** Return a function\n\n```javascript\nfunction sayHello() {\n   return function() {\n      console.log(\"Hello!\");\n   }\n}\n```\n\n**Example:** Using a variable\n\n```javascript\nconst sayHello = function() {\n   return function() {\n      console.log(\"Hello!\");\n   }\n}\nconst myFunc = sayHello();\nmyFunc();\n```\n\n**Example:** Using double parentheses\n\n```javascript\nfunction sayHello() {\n   return function() {\n      console.log(\"Hello!\");\n   }\n}\nsayHello()();\n```\nWe are using double parentheses `()()` to invoke the returned function as well.\n\n\u003cdiv align=\"right\"\u003e\n    \u003cb\u003e\u003ca href=\"#\"\u003e↥ back to top\u003c/a\u003e\u003c/b\u003e\n\u003c/div\u003e\n\n## Q. ***What is a higher order function?***\n\nA Higher-Order function is a function that receives a function as an argument or returns the function as output.\n\nFor example, `Array.prototype.map()`, `Array.prototype.filter()` and `Array.prototype.reduce()` are some of the Higher-Order functions in javascript.\n\n```javascript\nconst arr1 = [1, 2, 3];\nconst arr2 = arr1.map(function(item) {\n  return item * 2;\n});\nconsole.log(arr2);\n```\n\u003cdiv align=\"right\"\u003e\n    \u003cb\u003e\u003ca href=\"#\"\u003e↥ back to top\u003c/a\u003e\u003c/b\u003e\n\u003c/div\u003e\n\n## Q. ***What is a unary function?***\n\nUnary function (i.e. monadic) is a function that accepts exactly one argument. Let us take an example of unary function. It stands for single argument accepted by a function.\n\n```javascript\nconst unaryFunction = a =\u003e console.log (a + 10); //Add 10 to the given argument and display the value\n```\n\u003cdiv align=\"right\"\u003e\n    \u003cb\u003e\u003ca href=\"#\"\u003e↥ back to top\u003c/a\u003e\u003c/b\u003e\n\u003c/div\u003e\n\n## Q. ***What is currying function?***\n\nCurrying is the process of taking a function with multiple arguments and turning it into a sequence of functions each with only a single argument.\n\n```javascript\nfunction volume(length) {\n  return function(width) {\n    return function(height) {\n      return height * width * length;\n    }\n  }\n}\n\nvolume(2)(3)(4); // 24\n```\nCurried functions are great to improve code re-usability and functional composition.\n\n\u003cdiv align=\"right\"\u003e\n    \u003cb\u003e\u003ca href=\"#\"\u003e↥ back to top\u003c/a\u003e\u003c/b\u003e\n\u003c/div\u003e\n\n## Q. ***What is a pure function?***\n\nPure functions are functions that accept an input and returns a value without modifying any data outside its scope(Side Effects). Its output or return value must depend on the input/arguments and pure functions must return a value.\n\n**Example**\n\n```javascript\nfunction impure(arg) {\n    finalR.s = 90\n    return arg * finalR.s\n}\n```\nThe above function is not a pure function because it modified a state `finalR.s` outside its scope.\n\n```javascript\nfunction pure(arg) {\n    return arg * 4\n}\n```\nHere is a pure function. It didn’t side effect any external state and it returns an output based on the input.\n\nA function must pass two tests to be considered “pure”:\n\n1. Same inputs always return same outputs\n1. No side-effects\n\n**1. Same Input =\u003e Same Output**  \nCompare this:\n\n```javascript\nconst add = (x, y) =\u003e x + y;\n\nadd(2, 4); // 6\n```\nTo this\n\n```javascript\nlet x = 2;\n\nconst add = (y) =\u003e {\n  x += y;\n};\n\nadd(4); // x === 6 (the first time)\n```\n**2. Pure Functions = Consistent Results**  \nThe first example returns a value based on the given parameters, regardless of where/when you call it.\n\nIf you pass 2 and 4, you’ll always get 6.\n\nNothing else affects the output.\n\n**Benefits**  \n* One of the major benefits of using pure functions is they are immediately testable. They will always produce the same result if you pass in the same arguments.\n* The pure functions are easier to parallelize\n* They also makes maintaining and refactoring code much easier.\n\n\u003cdiv align=\"right\"\u003e\n    \u003cb\u003e\u003ca href=\"#\"\u003e↥ back to top\u003c/a\u003e\u003c/b\u003e\n\u003c/div\u003e\n\n## Q. ***What is memoization in JavaScript?***\n\nMemoization is a programming technique which attempts to increase a function’s performance by caching its previously computed results.  Each time a memoized function is called, its parameters are used to index the cache. If the data is present, then it can be returned, without executing the entire function. Otherwise the function is executed and then the result is added to the cache.\n\n```javascript\n// A simple memoized function to Add Number\nconst memoizedAdd = () =\u003e {\n  let cache = {};\n  return (number) =\u003e {\n    if (number in cache) {\n      console.log('Fetching from cache: ');\n      return cache[number];\n    }\n    else {\n      console.log('Calculating result: ');\n      let result = number + 10;\n      cache[number] = result;\n      return result;\n    }\n  }\n}\n// returned function from memoizedAdd\nconst sum = memoizedAdd();\nconsole.log(sum(10)); // Calculating result: 20\nconsole.log(sum(10)); // Fetching from cache: 20\n```\n\n\u003cdiv align=\"right\"\u003e\n    \u003cb\u003e\u003ca href=\"#\"\u003e↥ back to top\u003c/a\u003e\u003c/b\u003e\n\u003c/div\u003e\n\n## Q. ***What is a service worker?***\n\nA Service worker is basically a JavaScript file that runs in background, separate from a web page and provide features that don't need a web page or user interaction. \n\nSome of the major features of service workers are \n* Offline first web application development\n* Periodic background syncs, push notifications\n* Intercept and handle network requests\n* Programmatically managing a cache of responses\n\n**Lifecycle of a Service Worker**\n\nIt consists of the following phases:\n* Download\n* Installation\n* Activation\n\n**Registering a Service Worker**\n\nTo register a service worker we first check if the browser supports it and then register it.\n\n```javascript\nif ('serviceWorker' in navigator) {\n  navigator.serviceWorker.register('/ServiceWorker.js')\n  .then(function(response) {\n\n    // Service worker registration done\n    console.log('Registration Successful', response);\n  }, function(error) {\n    // Service worker registration failed\n    console.log('Registration Failed', error);\n  }\n```\n\n**Installation of service worker**\n\nAfter the controlled page that takes care of the registration process, we come to the service worker script that handles the installation part.\n\nBasically, you will need to define a callback for the install event and then decide on the files that you wish to cache. Inside a callback, one needs to take of the following three points –\n\n* Open a cache\n* Cache the files\n* Seek confirmation for the required caches and whether they have been successful.\n\n```javascript\nvar CACHENAME = 'My site cache'; \nvar urlstocache = [ \n\t'/', \n  '/styles/main1.css', \n\t'/script/main1.js' \n]; \nself.addEventListener('install', function(event) { \n\t// Performing installation steps \n\tevent.waitUntil( \n\t\tcaches.open(CACHENAME) \n\t\t.then(function(cache) { \n\t\t\tconsole.log('Opening of cache'); \n\t\t\treturn cache.addAll(urlstocache);\n\t\t}) \n);\n```\n\n**Cache and return requests**\n\nAfter a service worker is installed and the user navigates to a different page or refreshes, the service worker will begin to receive fetch events, an example of which is below.\n\n```javascript\nself.addEventListener('fetch', function(event) {\n  event.respondWith(\n    caches.match(event.request)\n      .then(function(response) {\n        // Cache hit - return response\n        if (response) {\n          return response;\n        }\n        return fetch(event.request);\n      }\n    )\n  );\n});\n```\n\n\u003cdiv align=\"right\"\u003e\n    \u003cb\u003e\u003ca href=\"#\"\u003e↥ back to top\u003c/a\u003e\u003c/b\u003e\n\u003c/div\u003e\n\n## Q. ***How do you manipulate DOM using service worker?***\n\nService worker can\\'t access the DOM directly. But it can communicate with the pages it controls by responding to messages sent via the `postMessage` interface, and those pages can manipulate the DOM.\n\n**Example:** service-worker.html\n```html\n\u003c!doctype html\u003e\n\u003chtml\u003e\n\u003chead\u003e\n\u003cmeta charset=\"UTF-8\"\u003e\n\u003ctitle\u003eService Worker\u003c/title\u003e\n\u003c/head\u003e\n\u003cbody\u003e\n(Look in the console.)\n\u003cscript\u003e\n(function() {\n    \"use strict\";\n\n    if (!navigator.serviceWorker || !navigator.serviceWorker.register) {\n        console.log(\"This browser doesn't support service workers\");\n        return;\n    }\n\n    // Listen to messages from service workers.\n    navigator.serviceWorker.addEventListener('message', function(event) {\n        console.log(\"Got reply from service worker: \" + event.data);\n    });\n\n    // Are we being controlled?\n    if (navigator.serviceWorker.controller) {\n        // Yes, send our controller a message.\n        console.log(\"Sending 'hi' to controller\");\n        navigator.serviceWorker.controller.postMessage(\"hi\");\n    } else {\n        // No, register a service worker to control pages like us.\n        // Note that it won't control this instance of this page, it only takes effect\n        // for pages in its scope loaded *after* It is installed.\n        navigator.serviceWorker.register(\"service-worker.js\")\n            .then(function(registration) {\n                console.log(\"Service worker registered, scope: \" + registration.scope);\n                console.log(\"Refresh the page to talk to it.\");\n                // If we want to, we might do `location.reload();` so that we'd be controlled by it\n            })\n            .catch(function(error) {\n                console.log(\"Service worker registration failed: \" + error.message);\n            });\n    }\n})();\n\u003c/script\u003e\n\u003c/body\u003e\n\u003c/html\u003e\n```\n\n**service-worker.js** \n\n```javascript\nself.addEventListener(\"message\", function(event) {\n    //event.source.postMessage(\"Responding to \" + event.data);\n    self.clients.matchAll().then(all =\u003e all.forEach(client =\u003e {\n        client.postMessage(\"Responding to \" + event.data);\n    }));\n});\n```\n\n\u003cdiv align=\"right\"\u003e\n    \u003cb\u003e\u003ca href=\"#\"\u003e↥ back to top\u003c/a\u003e\u003c/b\u003e\n\u003c/div\u003e\n\n## Q. ***How do you reuse information across service worker restarts?***\n\nThe problem with service worker is that it get terminated when not in use, and restarted when it is next needed, so you cannot rely on global state within a service worker `onfetch` and `onmessage` handlers. In this case, service workers will have access to IndexedDB API in order to persist and reuse across restarts.\n\n\u003cdiv align=\"right\"\u003e\n    \u003cb\u003e\u003ca href=\"#\"\u003e↥ back to top\u003c/a\u003e\u003c/b\u003e\n\u003c/div\u003e\n\n## Q. ***What is a post message?***\n\nPost message is a method that enables cross-origin communication between Window objects.(i.e, between a page and a pop-up that it spawned, or between a page and an iframe embedded within it). Generally, scripts on different pages are allowed to access each other if and only if the pages follow same-origin policy(i.e, pages share the same protocol, port number, and host).\n\n\u003cdiv align=\"right\"\u003e\n    \u003cb\u003e\u003ca href=\"#\"\u003e↥ back to top\u003c/a\u003e\u003c/b\u003e\n\u003c/div\u003e\n\n## Q. ***What is a web-storage event and its event handler?***\n\nThe StorageEvent is an event that fires when a storage area has been changed in the context of another document. Whereas onstorage property is an EventHandler for processing storage events.\nThe syntax would be as below\n\n```javascript\n  window.onstorage = functionRef;\n```\n\nLet us take the example usage of onstorage event handler which logs the storage key and its values\n\n```javascript\nif (typeof(Storage) !== \"undefined\") {\n  window.onstorage = function(e) {\n    console.log('The ' + e.key +\n      ' key has been changed from ' + e.oldValue +\n      ' to ' + e.newValue + '.');\n  };\n} else {\n  // Browser doesnot support web-storage \n}\n```\n\n\u003cdiv align=\"right\"\u003e\n    \u003cb\u003e\u003ca href=\"#\"\u003e↥ back to top\u003c/a\u003e\u003c/b\u003e\n\u003c/div\u003e\n\n## Q. ***How to use Web Workers in javascript?***\n\n**Step 01: Create a Web Workers file**: Write a script to increment the count value.\n\n```javascript\n// counter.js\nlet i = 0;\n\nfunction timedCount() {\n  i = i + 1;\n  postMessage(i);\n  setTimeout(\"timedCount()\",500);\n}\n\ntimedCount();\n```\n\nHere `postMessage()` method is used to post a message back to the HTML page.  \n\n**Step 02: Create a Web Worker Object**: Create a web worker object by checking for browser support.\n\n```javascript\nif (typeof(w) == \"undefined\") {\n  w = new Worker(\"counter.js\");\n}\n```\nand we can receive messages from web workers\n\n```javascript\nw.onmessage = function(event){\n  document.getElementById(\"message\").innerHTML = event.data;\n};\n```\n**Step 03: Terminate a Web Workers**: Web workers will continue to listen for messages (even after the external script is finished) until it is terminated. You can use terminate() method to terminate listening the messages.\n\n```javascript\nw.terminate();\n```\n\n**Step 04: Reuse the Web Workers**: If you set the worker variable to undefined you can reuse the code\n\n```javascript\nw = undefined;\n```\n\nExample:\n```html\n\u003c!DOCTYPE html\u003e\n\u003chtml\u003e\n\u003cbody\u003e\n  \u003cp\u003eCount numbers: \u003coutput id=\"result\"\u003e\u003c/output\u003e\u003c/p\u003e\n  \u003cbutton onclick=\"startWorker()\"\u003eStart\u003c/button\u003e\n  \u003cbutton onclick=\"stopWorker()\"\u003eStop\u003c/button\u003e\n  \n  \u003cscript\u003e\n    var w;\n\n    function startWorker() {\n      if (typeof(Worker) !== \"undefined\") {\n        if (typeof(w) == \"undefined\") {\n          w = new Worker(\"counter.js\");\n        }\n        w.onmessage = function(event) {\n          document.getElementById(\"result\").innerHTML = event.data;\n        };\n      } else {\n        document.getElementById(\"result\").innerHTML = \"Sorry! No Web Worker support.\";\n      }\n    }\n\n    function stopWorker() {\n      w.terminate();\n      w = undefined;\n    }\n  \u003c/script\u003e\n\u003c/body\u003e\n\u003c/html\u003e\n```\n\n\u003cdiv align=\"right\"\u003e\n    \u003cb\u003e\u003ca href=\"#\"\u003e↥ back to top\u003c/a\u003e\u003c/b\u003e\n\u003c/div\u003e\n\n## Q. ***What are the restrictions of web workers on DOM?***\n\nWebWorkers do not have access to below javascript objects since they are defined in an external files\n1. Window object\n2. Document object\n3. Parent object\n\n\u003cdiv align=\"right\"\u003e\n    \u003cb\u003e\u003ca href=\"#\"\u003e↥ back to top\u003c/a\u003e\u003c/b\u003e\n\u003c/div\u003e\n\n## Q. ***What is a promise?***\n\nA promise is an object that may produce a single value some time in the future with either a resolved value or a reason that it’s not resolved(for example, network error). It will be in one of the 3 possible states: fulfilled, rejected, or pending.\nSyntax\n\n```javascript\nconst promise = new Promise(function(resolve, reject) {\n  // promise description\n})\n```\n\nPromises are used to handle asynchronous operations. They provide an alternative approach for callbacks by reducing the callback hell and writing the cleaner code.\n\nPromises have three states:\n1. **Pending:** This is an initial state of the Promise before an operation begins\n2. **Fulfilled:** This state indicates that specified operation was completed.\n3. **Rejected:** This state indicates that the operation did not complete. In this case an error value will be thrown.\n\n\u003cdiv align=\"right\"\u003e\n    \u003cb\u003e\u003ca href=\"#\"\u003e↥ back to top\u003c/a\u003e\u003c/b\u003e\n\u003c/div\u003e\n\n## Q. ***What is a callback function?***\n\nA callback function is a function passed into another function as an argument. This function is invoked inside the outer function to complete an action.\n\n```javascript\nfunction callbackFunction(name) {\n  console.log('Hello ' + name);\n}\n\nfunction outerFunction(callback) {\n  let name = prompt('Please enter your name.');\n  callback(name);\n}\n\nouterFunction(callbackFunction);\n```\n\n\u003cdiv align=\"right\"\u003e\n    \u003cb\u003e\u003ca href=\"#\"\u003e↥ back to top\u003c/a\u003e\u003c/b\u003e\n\u003c/div\u003e\n\n## Q. ***Why do we need callbacks?***\n\nThe callbacks are needed because javascript is a event driven language. That means instead of waiting for a response javascript will keep executing while listening for other events.\n\nLet us take an example with first function invoking an API call(simulated by setTimeout) and next function which logs the message.\n\n```javascript\nfunction firstFunction() {\n  // Simulate a code delay\n  setTimeout( function() {\n    console.log('First function called');\n  }, 1000 );\n}\nfunction secondFunction() {\n  console.log('Second function called');\n}\nfirstFunction();\nsecondFunction();\n\nOutput\n// Second function called\n// First function called\n```\nAs observed from the output, javascript didnot wait for the response of first function and remaining code block get executed. So callbacks used in a way to make sure that certain code does not execute until other code finished execution.\n\n\u003cdiv align=\"right\"\u003e\n    \u003cb\u003e\u003ca href=\"#\"\u003e↥ back to top\u003c/a\u003e\u003c/b\u003e\n\u003c/div\u003e\n\n## Q. ***What is a callback hell?***\n\nCallback Hell is an anti-pattern with multiple nested callbacks which makes code hard to read and debug when dealing with asynchronous logic. The callback hell looks like below,\n\n```javascript\nasync1(function() {\n    async2(function() {\n        async3(function() {\n            async4(function() {\n                ....\n            });\n        });\n    });\n});\n```\n\n\u003cdiv align=\"right\"\u003e\n    \u003cb\u003e\u003ca href=\"#\"\u003e↥ back to top\u003c/a\u003e\u003c/b\u003e\n\u003c/div\u003e\n\n## Q. ***What is server-sent events?***\n\nServer-sent events (SSE) is a server push technology enabling a browser to receive automatic updates from a server via HTTP connection without resorting to polling. These are a one way communications channel - events flow from server to client only. This is been used in Facebook/Twitter updates, stock price updates, news feeds etc.\n\nThe `EventSource` object is used to receive server-sent event notifications. For example, we can receive messages from server as below,\n\n```javascript\nif(typeof(EventSource) !== \"undefined\") {\n  var source = new EventSource(\"sse_generator.js\");\n  source.onmessage = function(event) {\n    document.getElementById(\"output\").innerHTML += event.data + \"\u003cbr\u003e\";\n  };\n}\n```\nBelow are the list of events available for server sent events\n\n| Event | Description |\n|------ |--------------|\n| onopen  | It is used when a connection to the server is opened |\n| onmessage | This event is used when a message is received  |\n| onerror | It happens when an error occurs|\n\n\u003cdiv align=\"right\"\u003e\n    \u003cb\u003e\u003ca href=\"#\"\u003e↥ back to top\u003c/a\u003e\u003c/b\u003e\n\u003c/div\u003e\n\n## Q. ***What is callback in callback?***\n\nYou can nest one callback inside in another callback to execute the actions sequentially one by one. This is known as callbacks in callbacks.\n\n```javascript\nloadScript('/script1.js', function(script) {\n    console.log('first script is loaded');\n\n  loadScript('/script2.js', function(script) {\n\n    console.log('second script is loaded');\n\n    loadScript('/script3.js', function(script) {\n\n        console.log('third script is loaded');\n      // after all scripts are loaded\n    });\n  })\n});\n```\n\u003cdiv align=\"right\"\u003e\n    \u003cb\u003e\u003ca href=\"#\"\u003e↥ back to top\u003c/a\u003e\u003c/b\u003e\n\u003c/div\u003e\n\n## Q. ***What is promise chaining?***\n\nThe process of executing a sequence of asynchronous tasks one after another using promises is known as Promise chaining.\n\n```javascript\nnew Promise(function(resolve, reject) {\n\n  setTimeout(() =\u003e resolve(1), 1000);\n\n}).then(function(result) {\n\n  console.log(result); // 1\n  return result * 2;\n\n}).then(function(result) {\n\n  console.log(result); // 2\n  return result * 3;\n\n}).then(function(result) {\n\n  console.log(result); // 6\n  return result * 4;\n\n});\n```\nIn the above handlers, the result is passed to the chain of .then() handlers with the below work flow,\n1. The initial promise resolves in 1 second,\n2. After that `.then` handler is called by logging the result(1) and then return a promise with the value of result * 2.\n3. After that the value passed to the next `.then` handler by logging the result(2) and return a promise with result * 3.\n4. Finally the value passed to the last `.then` handler by logging the result(6) and return a promise with result * 4.\n\n\u003cdiv align=\"right\"\u003e\n    \u003cb\u003e\u003ca href=\"#\"\u003e↥ back to top\u003c/a\u003e\u003c/b\u003e\n\u003c/div\u003e\n\n## Q. ***What is promise.all()?***\n\n`Promise.all` is a promise that takes an array of promises as an input (an iterable), and it gets resolved when all the promises get resolved or any one of them gets rejected.\n\n```javascript\nPromise.all([Promise1, Promise2, Promise3]) \n        .then(result) =\u003e {   \n            console.log(result) \n          }) \n        .catch(error =\u003e console.log(`Error in promises ${error}`));\n```\n*Note: Remember that the order of the promises(output the result) is maintained as per input order*.\n\n\u003cdiv align=\"right\"\u003e\n    \u003cb\u003e\u003ca href=\"#\"\u003e↥ back to top\u003c/a\u003e\u003c/b\u003e\n\u003c/div\u003e\n\n## Q. ***What is the purpose of race method in promise?***\n\n`Promise.race()` method will return the promise instance which is firstly resolved or rejected. Let us take an example of race() method where promise2 is resolved first\n\n```javascript\nvar promise1 = new Promise(function(resolve, reject) {\n    setTimeout(resolve, 500, 'one');\n});\nvar promise2 = new Promise(function(resolve, reject) {\n    setTimeout(resolve, 100, 'two');\n});\n\nPromise.race([promise1, promise2]).then(function(value) {\n  console.log(value); // \"two\" // Both promises will resolve, but promise2 is faster\n});\n```\n\u003cdiv align=\"right\"\u003e\n    \u003cb\u003e\u003ca href=\"#\"\u003e↥ back to top\u003c/a\u003e\u003c/b\u003e\n\u003c/div\u003e\n\n## Q. ***What is a strict mode in javascript?***\n\nStrict Mode is a new feature in ECMAScript 5 that allows to place a program, or a function, in a **strict** operating context. This way it prevents certain actions from being taken and throws more exceptions. The literal expression `'use strict';` instructs the browser to use the javascript code in the Strict mode.\n\nStrict mode is useful to write **secure javaScript** by notifying \"bad syntax\" into real errors. For example, it eliminates accidentally creating a global variable by throwing an error and also throws an error for assignment to a non-writable property, a getter-only property, a non-existing property, a non-existing variable, or a non-existing object.\n\nThe strict mode is declared by adding \"use strict\"; to the beginning of a script or a function.\nIf declare at the beginning of a script, it has global scope.\n\n```javascript\n'use strict';\nx = 3.14; // This will cause an error because x is not declared\n```\nand if you declare inside a function, it has local scope\n\n```javascript\nx = 3.14;       // This will not cause an error.\nmyFunction();\n\nfunction myFunction() {\n  'use strict';\n  y = 3.14;   // This will cause an error\n}\n```\n\u003cdiv align=\"right\"\u003e\n    \u003cb\u003e\u003ca href=\"#\"\u003e↥ back to top\u003c/a\u003e\u003c/b\u003e\n\u003c/div\u003e\n\n## Q. ***What is the purpose of double exclamation?***\n\nThe double exclamation or negation(!!) ensures the resulting type is a boolean. If it was falsey (e.g. 0, null, undefined, etc.), it will be false, otherwise, true.\nFor example, you can test IE version using this expression as below,\n\n```javascript\nlet isIE11 = false;\nisIE11 = !!navigator.userAgent.match(/Trident.*rv[ :]*11\\./);\nconsole.log(isIE11); // returns true or false\n```\nIf you do not use this expression then it returns the original value.\n\n```javascript\nconsole.log(navigator.userAgent.match(/Trident.*rv[ :]*11\\./));  // returns either an Array or null\n```\n*Note: The expression !! is not an operator, but it is just twice of ! operator*.\n\n\u003cdiv align=\"right\"\u003e\n    \u003cb\u003e\u003ca href=\"#\"\u003e↥ back to top\u003c/a\u003e\u003c/b\u003e\n\u003c/div\u003e\n\n## Q. ***What is the purpose of delete operator?***\n\nThe delete keyword is used to delete the property as well as its value.\n\n```javascript\nvar user= {name: \"John\", age:20};\ndelete user.age;\n\nconsole.log(user); // {name: \"John\"}\n```\n\u003cdiv align=\"right\"\u003e\n    \u003cb\u003e\u003ca href=\"#\"\u003e↥ back to top\u003c/a\u003e\u003c/b\u003e\n\u003c/div\u003e\n\n## Q. ***What is typeof operator?***\n\nYou can use the JavaScript typeof operator to find the type of a JavaScript variable. It returns the type of a variable or an expression.\n\n```javascript\ntypeof \"John Abraham\"     // Returns \"string\"\ntypeof (1 + 2)        // Returns \"number\"\n```\n\u003cdiv align=\"right\"\u003e\n    \u003cb\u003e\u003ca href=\"#\"\u003e↥ back to top\u003c/a\u003e\u003c/b\u003e\n\u003c/div\u003e\n\n## Q. ***What is undefined property?***\n\nThe undefined property indicates that a variable has not been assigned a value, or not declared at all. The type of undefined value is undefined too.\n\n```javascript\nvar user;    // Value is undefined, type is undefined\nconsole.log(typeof(user)) //undefined\n```\nAny variable can be emptied by setting the value to undefined.\n\n```javascript\nuser = undefined\n```\n\u003cdiv align=\"right\"\u003e\n    \u003cb\u003e\u003ca href=\"#\"\u003e↥ back to top\u003c/a\u003e\u003c/b\u003e\n\u003c/div\u003e\n\n## Q. ***What is the difference between null and undefined?***\n\nBelow are the main differences between null and undefined,\n\n| Null | Undefined |\n|---- | -----------|\n| It is an assignment value which indicates that variable points to no object.  | It is not an assignment value where a variable has been declared but has not yet been assigned a value. |\n| Type of null is object | Type of undefined is undefined  |\n| The null value is a primitive value that represents the null, empty, or non-existent reference. | The undefined value is a primitive value used when a variable has not been assigned a value.|\n| Indicates the absence of a value for a variable | Indicates absence of variable itself |\n| Converted to zero (0) while performing primitive operations | Converted to NaN while performing primitive operations |\n\n\u003cdiv align=\"right\"\u003e\n    \u003cb\u003e\u003ca href=\"#\"\u003e↥ back to top\u003c/a\u003e\u003c/b\u003e\n\u003c/div\u003e\n\n## Q. ***What is eval?***\n\nThe eval() function evaluates JavaScript code represented as a string. The string can be a JavaScript expression, variable, statement, or sequence of statements.\n\n```javascript\nconsole.log(eval('1 + 2')); //  3\n```\n\u003cdiv align=\"right\"\u003e\n    \u003cb\u003e\u003ca href=\"#\"\u003e↥ back to top\u003c/a\u003e\u003c/b\u003e\n\u003c/div\u003e\n\n## Q. ***What is the difference between window and document?***\n\nThe window is the first thing that gets loaded into the browser. This window object has the majority of the properties like length, innerWidth, innerHeight, name, if it has been closed, its parents, and more.\n\nThe document object is html, aspx, php, or other document that will be loaded into the browser. The document actually gets loaded inside the window object and has properties available to it like title, URL, cookie, etc.\n\n| Window | Document |\n|------- | ---------|\n| 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) |\n| By default window object is available implicitly in the page | You can access it via window.document or document.  |\n| It has methods like alert(), confirm() and properties like document, location | It provides methods like getElementById(), getElementByTagName(), createElement() etc  |\n\n\u003cdiv align=\"right\"\u003e\n    \u003cb\u003e\u003ca href=\"#\"\u003e↥ back to top\u003c/a\u003e\u003c/b\u003e\n\u003c/div\u003e\n\n## Q. ***How do you access history in javascript?***\n\nThe window.history object contains the browsers history. You can load previous and next URLs in the history using back() and next() methods.\n\n```javascript\nfunction goBack() {\n  window.history.back()\n}\nfunction goForward() {\n  window.history.forward()\n}\n```\n*Note: You can also access history without window prefix*.\n\n\u003cdiv align=\"right\"\u003e\n    \u003cb\u003e\u003ca href=\"#\"\u003e↥ back to top\u003c/a\u003e\u003c/b\u003e\n\u003c/div\u003e\n\n## Q. ***What is isNaN?***\n\nThe isNaN() function is used to determine whether a value is an illegal number (Not-a-Number) or not. i.e, This function returns true if the value equates to NaN. Otherwise it returns false.\n\n```javascript\nisNaN('Hello') //true\nisNaN('100') //false\ntypeof(NaN) //Number\n```\n\u003cdiv align=\"right\"\u003e\n    \u003cb\u003e\u003ca href=\"#\"\u003e↥ back to top\u003c/a\u003e\u003c/b\u003e\n\u003c/div\u003e\n\n## Q. ***What are the differences between undeclared and undefined variables?***\n\nBelow are the major differences between undeclared and undefined variables,\n\n| undeclared | undefined |\n|---- | ---------\n| These variables do not exist in a program and are not declared  | These variables declared in the program but have not assigned any value |\n| 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.  |\n\n\u003cdiv align=\"right\"\u003e\n    \u003cb\u003e\u003ca href=\"#\"\u003e↥ back to top\u003c/a\u003e\u003c/b\u003e\n\u003c/div\u003e\n\n## Q. ***What is NaN property?***\n\nThe NaN property is a global property that represents \"Not-a-Number\" value. i.e, It indicates that a value is not a legal number. It is very rare to use NaN in a program but it can be used as return value for few cases\n\n```javascript\nMath.sqrt(-1)\nparseInt(\"Hello\")\n```\n\u003cdiv align=\"right\"\u003e\n    \u003cb\u003e\u003ca href=\"#\"\u003e↥ back to top\u003c/a\u003e\u003c/b\u003e\n\u003c/div\u003e\n\n## Q. ***What is the purpose of isFinite function?***\n\nThe isFinite() function is used to determine whether a number is a finite, legal number. It returns false if the value is +infinity, -infinity, or NaN (Not-a-Number), otherwise it returns true.\n\n```javascript\nisFinite(Infinity);  // false\nisFinite(NaN);       // false\nisFinite(-Infinity); // false\n\nisFinite(100);         // true\n```\n\u003cdiv align=\"right\"\u003e\n    \u003cb\u003e\u003ca href=\"#\"\u003e↥ back to top\u003c/a\u003e\u003c/b\u003e\n\u003c/div\u003e\n\n## Q. ***How do you submit a form using JavaScript?***\n\nYou can submit a form using JavaScript use document.form[0].submit(). All the form input information is submitted using onsubmit event handler\n\n```javascript\nfunction submit() {\n    document.form[0].submit();\n}\n```\n\n\u003cdiv align=\"right\"\u003e\n    \u003cb\u003e\u003ca href=\"#\"\u003e↥ back to top\u003c/a\u003e\u003c/b\u003e\n\u003c/div\u003e\n\n## Q. ***How do you find operating system details?***\n\nThe window.navigator object contains information about the visitor\\'s browser os details. Some of the OS properties are avaialble under platform property,\n\n```javascript\nconsole.log(navigator.platform);\n```\n\n\u003cdiv align=\"right\"\u003e\n    \u003cb\u003e\u003ca href=\"#\"\u003e↥ back to top\u003c/a\u003e\u003c/b\u003e\n\u003c/div\u003e\n\n## Q. ***What is the difference between document load and DOMContentLoaded events?***\n\nThe `DOMContentLoaded` event is fired when the initial HTML document has been completely loaded and parsed, without waiting for assets(stylesheets, images, and subframes) to finish loading. Whereas The load event is fired when the whole page has loaded, including all dependent resources(stylesheets, images).\n\n\u003cdiv align=\"right\"\u003e\n    \u003cb\u003e\u003ca href=\"#\"\u003e↥ back to top\u003c/a\u003e\u003c/b\u003e\n\u003c/div\u003e\n\n## Q. ***What is the difference between native, host and user objects?***\n\n* `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.\n* `Host objects` are objects provided by the browser or runtime environment (Node). For example, window, XmlHttpRequest, DOM nodes etc considered as host objects.\n* `User objects` are objects defined in the javascript code. For example, User object created for profile information.\n\n\u003cdiv align=\"right\"\u003e\n    \u003cb\u003e\u003ca href=\"#\"\u003e↥ back to top\u003c/a\u003e\u003c/b\u003e\n\u003c/div\u003e\n\n## Q. ***What are the pros and cons of promises over callbacks?***\n\nBelow are the list of pros and cons of promises over callbacks,  \n**Pros:**\n1. It avoids callback hell which is unreadable\n2. Easy to write sequential asynchronous code with .then()\n3. Easy to write parallel asynchronous code with Promise.all()\n4. Solves some of the common problems of callbacks(call the callback too late, too early, many times and swallow errors/exceptions)\n\n**Cons:**\n1. It makes little complex code\n2. You need to load a polyfill if ES6 is not supported\n\n\u003cdiv align=\"right\"\u003e\n    \u003cb\u003e\u003ca href=\"#\"\u003e↥ back to top\u003c/a\u003e\u003c/b\u003e\n\u003c/div\u003e\n\n## Q. ***What is the difference between an attribute and a property?***\n\nAttributes are defined on the HTML markup whereas properties are defined on the DOM. For example, the below HTML element has 2 attributes type and value,\n```html\n\u003cinput type=\"text\" value=\"Name:\"\u003e\n```\nYou can retrieve the attribute value as below,\n\n```javascript\nconst input = document.querySelector('input');\nconsole.log(input.getAttribute('value')); // Good morning\nconsole.log(input.value); // Good morning\n```\nAnd after you change the value of the text field to \"Good evening\", it becomes like\n\n```javascript\nconsole.log(input.getAttribute('value')); // Good morning\nconsole.log(input.value); // Good evening\n```\n\u003cdiv align=\"right\"\u003e\n    \u003cb\u003e\u003ca href=\"#\"\u003e↥ back to top\u003c/a\u003e\u003c/b\u003e\n\u003c/div\u003e\n\n## Q. ***What is same-origin policy?***\n\nThe same-origin policy is a policy that prevents JavaScript from making requests across domain boundaries. An origin is defined as a combination of URI scheme, hostname, and port number. If you enable this policy then it prevents a malicious script on one page from obtaining access to sensitive data on another web page using Document Object Model(DOM).\n\n\u003cdiv align=\"right\"\u003e\n    \u003cb\u003e\u003ca href=\"#\"\u003e↥ back to top\u003c/a\u003e\u003c/b\u003e\n\u003c/div\u003e\n\n## Q. ***What is the purpose of void(0)?***\n\nThe `void(0)` is used to prevent the page from refreshing. This will be helpful to eliminate the unwanted side-effect, because it will return the undefined primitive value. It is commonly used for HTML document that uses `href=\"JavaScript:void(0);\"` within an `\u003ca\u003e` element. i.e, when you click a link, the browser loads a new page or refreshes the same page. But this behavior will be prevented using this expression.  \nFor example, the below link notify the message without reloading the page\n```html\n\u003ca href=\"JavaScript:void(0);\" onclick=\"alert('Well done!')\"\u003eClick Me!\u003c/a\u003e\n```\n\u003cdiv align=\"right\"\u003e\n    \u003cb\u003e\u003ca href=\"#\"\u003e↥ back to top\u003c/a\u003e\u003c/b\u003e\n\u003c/div\u003e\n\n## Q. ***Is JavaScript a compiled or interpreted language?***\n\nJavaScript is an interpreted language, not a compiled language. An interpreter in the browser reads over the JavaScript code, interprets each line, and runs it. Nowadays  modern browsers use a technology known as Just-In-Time (JIT) compilation, which compiles JavaScript to executable bytecode just as it is about to run.\n\n\u003cdiv align=\"right\"\u003e\n    \u003cb\u003e\u003ca href=\"#\"\u003e↥ back to top\u003c/a\u003e\u003c/b\u003e\n\u003c/div\u003e\n\n## Q. ***Is JavaScript a case-sensitive language?***\n\nYes, JavaScript is a case sensitive language. The language keywords, variables, function \u0026 object names, and any other identifiers must always be typed with a consistent capitalization of letters.\n\n\u003cdiv align=\"right\"\u003e\n    \u003cb\u003e\u003ca href=\"#\"\u003e↥ back to top\u003c/a\u003e\u003c/b\u003e\n\u003c/div\u003e\n\n## Q. ***What are events?***\n\nEvents 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,\n\n1. Web page has finished loading\n2. Input field was changed\n3. Button was clicked\n\nExample: click event for button element\n\n```html\n\u003c!doctype html\u003e\n\u003chtml\u003e\n\u003chead\u003e\n  \u003cscript\u003e\n    function greeting() {\n      alert('Hello! Good morning');\n    }\n  \u003c/script\u003e\n\u003c/head\u003e\n\u003cbody\u003e\n  \u003cbutton type=\"button\" onclick=\"greeting()\"\u003eClick me\u003c/button\u003e\n\u003c/body\u003e\n\u003c/html\u003e\n```\n\n\u003cdiv align=\"right\"\u003e\n    \u003cb\u003e\u003ca href=\"#\"\u003e↥ back to top\u003c/a\u003e\u003c/b\u003e\n\u003c/div\u003e\n\n## Q. ***What is the use of preventDefault method?***\n\nThe 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 hyper link are some common usecases.\n\n```javascript\ndocument.getElementById(\"link\").addEventListener(\"click\", function(event) {\n   event.preventDefault();\n});\n```\n\n*Note: Remember that not all events are cancelable*.\n\n\u003cdiv align=\"right\"\u003e\n    \u003cb\u003e\u003ca href=\"#\"\u003e↥ back to top\u003c/a\u003e\u003c/b\u003e\n\u003c/div\u003e\n\n## Q. ***What is the use of stopPropagation method?***\n\nThe 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)\n```html\n\u003cp\u003eClick DIV1 Element\u003c/p\u003e\n\u003cdiv onclick=\"secondFunc()\"\u003eDIV 2\n  \u003cdiv onclick=\"firstFunc(event)\"\u003eDIV 1\u003c/div\u003e\n\u003c/div\u003e\n\n\u003cscript\u003e\nfunction firstFunc(event) {\n  alert(\"DIV 1\");\n  event.stopPropagation();\n}\n\nfunction secondFunc() {\n  alert(\"DIV 2\");\n}\n\u003c/script\u003e\n```\n\u003cdiv align=\"right\"\u003e\n    \u003cb\u003e\u003ca href=\"#\"\u003e↥ back to top\u003c/a\u003e\u003c/b\u003e\n\u003c/div\u003e\n\n## Q. ***What are the steps involved in return false usage?***\n\nThe return false statement in event handlers performs the below steps,\n1. First it stops the browser default action or behaviour.\n2. It prevents the event from propagating the DOM\n3. Stops callback execution and returns immediately when called.\n\n## Q. ***What is BOM?***\n\nThe 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 window. The Browser Object Model is not standardized and can change based on different browsers.\n\n\u003cdiv align=\"right\"\u003e\n    \u003cb\u003e\u003ca href=\"#\"\u003e↥ back to top\u003c/a\u003e\u003c/b\u003e\n\u003c/div\u003e\n\n## Q. ***What is the use of setTimeout?***\n\nThe setTimeout() method is used to call a function or evaluates an expression after a specified number of milliseconds. For example, let us log a message after 2 seconds using setTimeout method,\n\n```javascript\nsetTimeout(function() { console.log(\"Good morning\"); }, 2000);\n```\n\n\u003cdiv align=\"right\"\u003e\n    \u003cb\u003e\u003ca href=\"#\"\u003e↥ back to top\u003c/a\u003e\u003c/b\u003e\n\u003c/div\u003e\n\n## Q. ***What is the use of setInterval?***\n\nThe setInterval() method is used to call a function or evaluates an expression at specified intervals (in milliseconds). For example, let us log a message after 2 seconds using setInterval method,\n\n```javascript\nsetInterval(function() { console.log(\"Good morning\"); }, 2000);\n```\n\n\u003cdiv align=\"right\"\u003e\n    \u003cb\u003e\u003ca href=\"#\"\u003e↥ back to top\u003c/a\u003e\u003c/b\u003e\n\u003c/div\u003e\n\n## Q. ***Why is JavaScript treated as Single threaded?***\n\nJavaScript 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.\n\n\u003cdiv align=\"right\"\u003e\n    \u003cb\u003e\u003ca href=\"#\"\u003e↥ back to top\u003c/a\u003e\u003c/b\u003e\n\u003c/div\u003e\n\n## Q. ***What is an event delegation?***\n\nEvent 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.\nFor example, if you wanted to detect field changes in inside a specific form, you can use event delegation technique,\n\n```javascript\nvar form = document.querySelector('#registration-form');\n\n// Listen for changes to fields inside the form\nform.addEventListener('input', function (event) {\n\n// Log the field that was changed\nconsole.log(event.target);\n\n}, false);\n```\n\u003cdiv align=\"right\"\u003e\n    \u003cb\u003e\u003ca href=\"#\"\u003e↥ back to top\u003c/a\u003e\u003c/b\u003e\n\u003c/div\u003e\n\n## Q. ***What is the purpose JSON stringify?***\n\nWhen 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.\n\n```javascript\nvar userJSON = {'name': 'John', age: 31}\nvar userString = JSON.stringify(user);\nconsole.log(userString); //\"{\"name\":\"John\",\"age\":31}\"\n```\n\u003cdiv align=\"right\"\u003e\n    \u003cb\u003e\u003ca href=\"#\"\u003e↥ back to top\u003c/a\u003e\u003c/b\u003e\n\u003c/div\u003e\n\n## Q. ***How do you parse JSON string?***\n\nWhen receiving the data from a web server, the data is always in a string format. But you can convert this string value to javascript object using parse() method.\n\n```javascript\nvar userString = '{\"name\":\"John\",\"age\":31}';\nvar userJSON = JSON.parse(userString);\nconsole.log(userJSON);// {name: \"John\", age: 31}\n```\n\u003cdiv align=\"right\"\u003e\n    \u003cb\u003e\u003ca href=\"#\"\u003e↥ back to top\u003c/a\u003e\u003c/b\u003e\n\u003c/div\u003e\n\n## Q. ***What is the purpose of clearTimeout method?***\n\nThe `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.\nFor example, the below setTimeout method is used to display the message after 3 seconds. This timeout can be cleared by clearTimeout() method.\n\n```javascript\nvar msg;\nfunction greeting() {\n  alert('Good morning');\n}\nfunction start() {\n  msg =setTimeout(greeting, 3000);\n}\nfunction stop() {\n    clearTimeout(msg);\n}\n```\n\u003cdiv align=\"right\"\u003e\n    \u003cb\u003e\u003ca href=\"#\"\u003e↥ back to top\u003c/a\u003e\u003c/b\u003e\n\u003c/div\u003e\n\n## Q. ***What is the purpose of clearInterval method?***\n\nThe `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.\nFor example, the below setInterval method is used to display the message for every 3 seconds. This interval can be cleared by clearInterval() method.\n\n```javascript\nvar msg;\nfunction greeting() {\n  alert('Good morning');\n}\nfunction start() {\n  msg = setInterval(greeting, 3000);\n}\nfunction stop() {\n    clearInterval(msg);\n}\n```\n\u003cdiv align=\"right\"\u003e\n    \u003cb\u003e\u003ca href=\"#\"\u003e↥ back to top\u003c/a\u003e\u003c/b\u003e\n\u003c/div\u003e\n\n## Q. ***How do you redirect new page in javascript?***\n\nIn vanilla javascript, you can redirect to a new page using `location` property of window object. The syntax would be as follows,\n\n```javascript\nfunction redirect() {\n  window.location.href = 'newPage.html';\n}\n```\n\u003cdiv align=\"right\"\u003e\n    \u003cb\u003e\u003ca href=\"#\"\u003e↥ back to top\u003c/a\u003e\u003c/b\u003e\n\u003c/div\u003e\n\n## Q. ***How do you check whether a string contains a substring?***\n\nThere are 3 possible ways to check whether a string contains a substring or not,  \n**a.) Using includes:** ES6 provided `String.prototype.includes` method to test a string contains a substring\n\n```javascript\nvar mainString = \"hello\", subString = \"hell\";\nmainString.includes(subString)\n```\n**b.) Using indexOf:** In an ES5 or older environments, 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 exist in the main string.\n\n```javascript\nvar mainString = \"hello\", subString = \"hell\";\nmainString.indexOf(subString) !== -1\n```\n**c.) Using RegEx:** The advanced solution is using Regular expression test method(`RegExp.test`), which allows for testing for against regular expressions\n\n```javascript\nvar mainString = \"hello\", regex = \"/hell/\";\nregex.test(mainString)\n```\n\u003cdiv align=\"right\"\u003e\n    \u003cb\u003e\u003ca href=\"#\"\u003e↥ back to top\u003c/a\u003e\u003c/b\u003e\n\u003c/div\u003e\n\n## Q. ***How do you validate an email in javascript?***\n\nYou can validate an email in javascript using regular expressions. It is recommended to do validations on the server side instead client side. Because the javascript can be disabled on the client side.\n\n```javascript\nfunction validateEmail(email) {\n    var re = /^(([^\u003c\u003e()\\[\\]\\\\.,;:\\s@\"]+(\\.[^\u003c\u003e()\\[\\]\\\\.,;:\\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,}))$/;\n    return re.test(String(email).toLowerCase());\n}\n```\nThe above regular expression regular accepts unicode characters.\n\n\u003cdiv align=\"right\"\u003e\n    \u003cb\u003e\u003ca href=\"#\"\u003e↥ back to top\u003c/a\u003e\u003c/b\u003e\n\u003c/div\u003e\n\n## Q. ***How do you get the current url with javascript?***\n\nYou 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 purpose but this solution has issues in FF.\n\n```javascript\nconsole.log('location.href', window.location.href); // Returns full URL\n```\n\n\u003cdiv align=\"right\"\u003e\n    \u003cb\u003e\u003ca href=\"#\"\u003e↥ back to top\u003c/a\u003e\u003c/b\u003e\n\u003c/div\u003e\n\n## Q. ***What are the various url properties of location object?***\n\nThe below `Location` object properties can be used to access URL components of the page\n\n|Properties|Description|\n|----------|------------|\n|href      |The entire URL|\n|protocol  |The protocol of the URL|\n|host      |The hostname and port of the URL|\n|hostname  |The hostname of the URL|\n|port      |The port number in the URL|\n|pathname  |The path name of the URL|\n|search    |The query portion of the URL|\n|hash      |The anchor portion of the URL|\n\n\u003cdiv align=\"right\"\u003e\n    \u003cb\u003e\u003ca href=\"#\"\u003e↥ back to top\u003c/a\u003e\u003c/b\u003e\n\u003c/div\u003e\n\n## Q. ***How do get query string values in javascript?***\n\nYou can use URLSearchParams to get query string values in javascript. Let us see an example to get the client code value from URL query string,\n\n```javascript\nconst urlParams = new URLSearchParams(window.location.search);\nconst clientCode = urlParams.get('clientCode');\n```\n\u003cdiv align=\"right\"\u003e\n    \u003cb\u003e\u003ca href=\"#\"\u003e↥ back to top\u003c/a\u003e\u003c/b\u003e\n\u003c/div\u003e\n\n## Q. ***How do you check if a key exists in an object?***\n\n**a.) Using in operator:** You can use the in operator whether a key exists in an object or not\n\n```javascript\n\"key\" in obj\n```\nand If you want to check if a key doesn't exist, remember to use parenthesis,\n\n```javascript\n!(\"key\" in obj)\n```\n**b.) Using hasOwnProperty method:** You can use `hasOwnProperty` to particularly test for properties of the object instan","project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Faakashdeveloper%2Fjavascript-interview-question","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Faakashdeveloper%2Fjavascript-interview-question","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Faakashdeveloper%2Fjavascript-interview-question/lists"}