{"id":19093164,"url":"https://github.com/ufocoder/javascript.interview","last_synced_at":"2025-08-04T01:33:59.286Z","repository":{"id":92639551,"uuid":"76722871","full_name":"ufocoder/javascript.interview","owner":"ufocoder","description":"This documents contains the most actual and important questions for Javascript Developer position","archived":false,"fork":false,"pushed_at":"2020-10-02T07:14:07.000Z","size":52,"stargazers_count":57,"open_issues_count":2,"forks_count":23,"subscribers_count":4,"default_branch":"master","last_synced_at":"2025-06-26T09:04:54.518Z","etag":null,"topics":["interview","javascript"],"latest_commit_sha":null,"homepage":"","language":null,"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/ufocoder.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":"2016-12-17T12:28:00.000Z","updated_at":"2023-12-13T11:21:46.000Z","dependencies_parsed_at":"2023-03-10T02:00:15.386Z","dependency_job_id":null,"html_url":"https://github.com/ufocoder/javascript.interview","commit_stats":null,"previous_names":[],"tags_count":0,"template":false,"template_full_name":null,"purl":"pkg:github/ufocoder/javascript.interview","repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/ufocoder%2Fjavascript.interview","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/ufocoder%2Fjavascript.interview/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/ufocoder%2Fjavascript.interview/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/ufocoder%2Fjavascript.interview/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/ufocoder","download_url":"https://codeload.github.com/ufocoder/javascript.interview/tar.gz/refs/heads/master","sbom_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/ufocoder%2Fjavascript.interview/sbom","host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":268636302,"owners_count":24282074,"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","status":"online","status_checked_at":"2025-08-03T02:00:12.545Z","response_time":2577,"last_error":null,"robots_txt_status":"success","robots_txt_updated_at":"2025-07-24T06:49:26.215Z","robots_txt_url":"https://github.com/robots.txt","online":true,"can_crawl_api":true,"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":["interview","javascript"],"created_at":"2024-11-09T03:23:31.367Z","updated_at":"2025-08-04T01:33:59.236Z","avatar_url":"https://github.com/ufocoder.png","language":null,"funding_links":[],"categories":[],"sub_categories":[],"readme":"JavaScript Interview\n====================\n\nThis documents contains the most actual and important questions for JavaScript developer position. \nIt will help you to compose question list for your own interview or prepare to interview.\n\nTable of contents:\n\n* [Inheritance in JavaScript](#inheritance-in-javascript):\n    * [Theory](#theory):\n      - [What is functional inheritance pattern? How to create protected methods and private properties?](#question-i1-what-is-functional-inheritance-pattern-how-to-create-protected-methods-and-private-properties)\n    * [Practice](#practice):\n      - [Write `Object.create` polyfill](#question-i2-write-objectcreate-polyfill)\n      - [What will output the following code and why?](#question-i3-what-will-output-the-following-code-and-why)\n* [Closure in JavaScript](#closure-in-javascript):\n    * [Theory](#theory-1):\n      - [What is Closure in JavaScript?](#question-c1-what-is-closure-in-javascript)\n      - [Does any currying function have a closure?](#questions-c2-does-any-currying-function-have-a-closure-give-an-example-please)\n    * [Practice](#practice-1):\n      - [What will output the following code and why?](#question-c3-what-will-output-the-following-code-and-why)\n      - [Resolving example of problem code](#question-c4-resolving-example-of-problem-code)\n      - [Write `nextID` function](#question-c5-write-nextid-function-that-will-generate-id-incrementally-after-each-calling)\n* [Bind, apply and call function methods](#bind-apply-and-call-function-methods) \n    * [Practice](#practice-2):\n      - [Write `sum` function](#question-b1-write-sum-function)\n* [Hoisting in JavaScript](#hoisting-in-javascript):\n    * [Theory](#theory-2):\n      - [What is a hoisting in JavaScript](#question-h1-explain-what-is-hoisting-in-JavaScript)\n    * [Practice](#practice-3):\n      - [What will output the following code and why?](#question-h2-what-will-output-the-following-code-and-why)\n      - [What will output the following code and why?](#question-h3-what-will-output-the-following-code-and-why)\n      - [What will output the following code and why?](#question-h4-what-will-output-the-following-code-and-why)\n* [Event Loop](#event-loop)\n    * [Theory](#theory-3):\n      - [How works event loop in the browser JavaScript?](#question-el1-how-works-event-loop-in-the-browser-javascript)\n    * [Practice](#practice-4):\n      - [What will output the following code and why?](#question-el2-what-will-output-the-following-code-and-why)\n* [Scope in JavaScript](#scope-in-javascript)\n    * [Practice](#practice-5):\n      - [What will output the following code and why?](#question-s1-what-will-be-the-output-of-the-following-code-and-why)\n* [Booleans in JavaScript](#booleans-in-javascript)\n    * [Theory](#theory-4):\n      - [What are JavaScripts' falsy values?](#question-b1-how-many-falsy-values-does-javascript-have-name-all-of-them)\n\n## Inheritance in JavaScript\n\n### **Theory**\n\n### Question i1: What is functional inheritance pattern? How to create protected methods and private properties?\n\n### **Practice**\n\n### Question i2: Write `Object.create` polyfill\nFor implementing use this [kata](https://www.codewars.com/kata/58b3e68aa68b70accb000614) please.\n\n### Question i3: What will output the following code and why?\n\n```js\nvar baseObject = {\n  prop: 'Base value',\n  getProp: function() {\n    return this.prop;\n  }\n};\n\nvar otherObject = Object.create(baseObject);\n\notherObject.prop = \"Other value\";\n\nconsole.log(otherObject.getProp());\ndelete otherObject.prop;\nconsole.log(otherObject.getProp()); \n```\n\n**Answer**\n\nConsole will output:\n\n```\nOther value\nBase value\n```\n\n## Closure in JavaScript\n\n### **Theory**\n\n### Question c1: What is Closure in JavaScript?\n\n[MDN definition](https://developer.mozilla.org/en/docs/Web/JavaScript/Closures):\nClosures are functions that refer to independent (free) variables (variables that are used locally, but defined in an enclosing scope). In other words, these functions 'remember' the environment in which they were created.\n\n[JavaScript.isSexy](http://javascriptissexy.com/understand-javascript-closures-with-ease/): A closure is an function that has access to the outer (enclosing) function’s variables-scope chain.\n\n### Questions c2. Does any currying function have a closure? Give an example, please.\n\n**Example**\n\n```js\nconst addTwoThings = thingToAdd(2);\naddTwoThings(3); // -\u003e 5\n\nconst addTwoThings = thingToAdd(10);\naddTwoThings(30); // -\u003e 40\n```\n\n**Answer**\n\nCurrying functions consist of chaining closures that return inner functions. So in the case of `thingToAdd` you will have two separate closures that each return a single value that gets evaluated sequentially.\n\n#### Example implementation using ES6\n\n```js\nconst thingToAdd = (a) =\u003e (b) =\u003e a + b;\n```\n\n#### Example implementation showing Closures\n\n```js\nlet thingToAdd = function (a) {\n    return function (b) {\n        return a + b;\n    }\n}\n```\n\n### **Practice**\n\n### Question c3: What will output the following code and why?\n\n```js\nfunction outerFunction() {\n    var flag = undefined;\n\n    function innerFunction() {\n      if (true) {\n        flag = true;\n      } else {\n        var flag = false;\n      }\n\n      console.log(flag);\n    }\n\n    console.log(flag);\n    innerFunction();\n}\n\nouterFunction();\n```\n\n**Answer**\n\nConsole will output the followings:\n\n```\nundefined\ntrue\n```\n\n### Question c4: Resolving example of problem code\n\nWhat will output these example? \n\n```js\nfor (var i = 0; i \u003c 10; i++) {\n    setTimeout(function() {\n        console.log(i);\n    }, 1000);\n}\n```\n\nHow to fix it to output numbers from 0 to 9?\n\n**Answer**\n\nThey're several ways to resolve code above.\n\n1) By creating a [IIFE](https://en.wikipedia.org/wiki/Immediately-invoked_function_expression) (Immediately Invoked Function Expression):\n\n```js\nfor (var i = 0; i \u003c 10; i++) {\n    setTimeout((function(param) {\n        console.log(i);\n    })(i), 1000);\n}\n```\n\n2) By using ES6 feature, by using [let syntax](https://developer.mozilla.org/en/docs/Web/JavaScript/Reference/Statements/let) particularly:\n\n```js\nfor (let i = 0; i \u003c 10; i++) {\n    setTimeout(function() {\n        console.log(i);\n    }, 1000);\n}\n```\n\n3) By [binding](https://developer.mozilla.org/en/docs/Web/JavaScript/Reference/Global_Objects/Function/bind) `console.log` function: \n\n```js\nfor (var i = 0; i \u003c 10; i++) {\n    setTimeout(console.log.bind(console, i), 1000);\n}\n```\n\n### Question c5: Write `nextID` function that will generate ID incrementally after each calling\n\nThere's an example of function output:\n\n```js\nnextID(); // output: 1\nnextID(); // output: 2\nnextID(); // output: 3\n```\n\n**Answer**\n\nWe should use closure in [IIFE](https://en.wikipedia.org/wiki/Immediately-invoked_function_expression):\n\n```js\nvar nextID = (function() {\n    var id = 0;\n    return function() {\n        console.log(++id);\n    }\n})();\n```\n\n\n## Bind, apply and call function methods\n\n### **Practice**\n\n### Question b1: Write `sum` function\n\nThis function must meet conditions:\n\n```js\ntypeof sum(1) === 'function'\ntypeof sum(1)(2) === 'function'\ntypeof sum(1)(2)() === 'number'\n\nsum(1)() === 1\nsum(1,2)(3)() == 6\nsum(1,2)(3,4)() === 10\n```\n\n**Answer**\n\n```js\nfunction sum (fn) {\n  var sumArguments = Array.prototype.slice.call(arguments);\n    \n  return function sumInner() {\n      if (arguments.length) {\n          sumArguments = sumArguments.concat(Array.prototype.slice.call(arguments));\n\n          return sumInner;\n      } else {\n          return sumArguments.reduce(function(total, arg) {\n            return total + arg;\n          }, 0);\n      }\n  };\n}\n```\n\n## Hoisting in JavaScript\n\n### **Theory**\n\n### Question h1: Explain what is hoisting in JavaScript\n\n**Answer**\n\n[W3School](https://www.w3schools.com/js/js_hoisting.asp) Hoisting is JavaScript's default behavior of moving declarations to the top. In JavaScript, a variable can be declared after it has been used. In other words; a variable can be used before it has been declared.\n\n### **Practice**\n\n### Question h2: What will output the following code and why?\n\n```js\nvar a = 1; \nfunction bar() { \n    if (!a) { \n        var a = 10; \n    } \n    console.log(a); \n} \nbar();\n```\n\n**Answer**\n\nConsole will output:\n\n```\n10\n```\n\n### Question h3: What will output the following code and why?\n\n```js\nvar a = 1;\nfunction b() {\n    a = 10;\n    return;\n    function a() {}\n} \nb(); \nconsole.log(a);\n```\n\n**Answer**\n\nConsole will output:\n\n```\n1\n```\n### Question h4: What will output the following code and why?\n\n```js\nfunction test() { \n    foo(); \n    bar();\n    function foo() { \n        console.log('foo'); \n    }\n    var bar = function() { \n        console.log('bar'); \n    } \n} \ntest(); \n```\n\n**Answer**\n\nConsole will output:\n\n```\nfoo\nTypeError: bar is not a function\n```\n\n## Event Loop\n\n### **Theory**\n\n### Question el1: How works event loop in the browser JavaScript?\n\n**Answer**\n\nEvent Loop in the browser could be represented as the following code:\n\n```js\nwhile (eventLoop.waitForTask()) {  \n  const taskQueue = eventLoop.selectTaskQueue();\n  if (taskQueue.hasNextTask()) {\n    taskQueue.processNextTask();\n  }\n\n  const microtaskQueue = eventLoop.microTaskQueue;\n  while (microtaskQueue.hasNextMicrotask()) {\n    microtaskQueue.processNextMicrotask();\n  }\n\n  if (eventLoop.shouldRender()) {\n    eventLoop.render();\n  }\n}\n```\n\n[Check current presentation](http://slides.com/xufocoder/event-loop-in-the-browser-javascript)\n\n### Question el2: What is a \"Promise\" in JavaScript in regards to event loops?\n\n**Answer**\n\nA Promise is essentially an object that can produce a single value at some time in the future, either a value or the reason why it could not be resolved.  Developers can then attach callbacks to these objects to execute code once the value resolved by the Promise is available.  Promises are also known as microtasks of event loops.  This means it is basically a task that is queued to be recalled during the event loop.  Promises can also be chained, meaning they can be attached to other Promises. Each attached Promise, or \"child\" Promise, would therefore have a \"parent\" Promise, that has to be resolved before the child can execute.     \n\n### **Practice**\n\n### Question el3: What will output the following code and why?\n\n```js\nconsole.log('script start');\n\nsetTimeout(function() {\n  console.log('setTimeout');\n}, 0);\n\nPromise.resolve().then(function() {\n  console.log('promise1');\n}).then(function() {\n  console.log('promise2');\n});\n\nconsole.log('script end');\n```\n\n**Answer**\n\nConsole will output:\n\n```\nscript start\nscript end\npromise1\npromise2\nsetTimeout\n```\n\n## Scope in JavaScript\n\n### **Practice**\n\n### Question s1: What will be the output of the following code and why?\n\n```js\ntry {\n  console.log(a);\n} catch (e) {\n  try {\n    a = 10;\n    console.log(a);\n  } catch (e) {\n    console.log('bar');\n  }\n}\nlet a = 1;\n```\n\n**Answer**\n\nConsole will output:\n\n```\nbar\n```\n\nReason:\n\nSince `let` is uninitialized at any time until being declared (unlike `var` which is always initialized but with value `undefined`), the first attempt to `console.log(a)` will raise an error which will be caught by the catch block. Then, inside that catch block, there's `a = 10` inside a try block again. This will also raise an error because there's still no variable named `a` so the catch block will catch the error once again so the output will be `bar`.\n\n## Booleans in JavaScript\n### **Theory**\n\n### Question b1: How many falsy values does JavaScript have? Name all of them\n\n**Answer**\nJavaScript has the following `7` falsy values:\n- `0` (integer)\n- `0n` (BigInt)\n- `null`\n- `undefined`\n- `false`\n- `NaN`\n- `\"\"`, `''` or `` (empty string)\n\n## Contributing\n\nI would be thankful for your [issues](https://github.com/ufocoder/javascript.interview/issues) and [pull requests](https://github.com/ufocoder/javascript.interview/pulls).\n","project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fufocoder%2Fjavascript.interview","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Fufocoder%2Fjavascript.interview","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fufocoder%2Fjavascript.interview/lists"}