{"id":13432669,"url":"https://github.com/kennymkchan/interview-questions-in-javascript","last_synced_at":"2025-03-17T10:32:24.184Z","repository":{"id":38415810,"uuid":"53985630","full_name":"kennymkchan/interview-questions-in-javascript","owner":"kennymkchan","description":"A mostly reasonable collection of technical software development interview questions solved in Javascript","archived":false,"fork":false,"pushed_at":"2019-09-30T22:25:26.000Z","size":48,"stargazers_count":3611,"open_issues_count":4,"forks_count":441,"subscribers_count":94,"default_branch":"master","last_synced_at":"2024-10-27T13:02:07.148Z","etag":null,"topics":["array","interview-practice","interview-questions","interviews","javascript","recursion","stack","strings"],"latest_commit_sha":null,"homepage":null,"language":null,"has_issues":true,"has_wiki":null,"has_pages":null,"mirror_url":null,"source_name":null,"license":"mit","status":null,"scm":"git","pull_requests_enabled":true,"icon_url":"https://github.com/kennymkchan.png","metadata":{"files":{"readme":"README.md","changelog":null,"contributing":null,"funding":null,"license":"LICENSE.txt","code_of_conduct":null,"threat_model":null,"audit":null,"citation":null,"codeowners":null,"security":null,"support":null}},"created_at":"2016-03-15T23:22:08.000Z","updated_at":"2024-10-26T21:19:11.000Z","dependencies_parsed_at":"2022-07-11T19:50:01.849Z","dependency_job_id":null,"html_url":"https://github.com/kennymkchan/interview-questions-in-javascript","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/kennymkchan%2Finterview-questions-in-javascript","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/kennymkchan%2Finterview-questions-in-javascript/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/kennymkchan%2Finterview-questions-in-javascript/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/kennymkchan%2Finterview-questions-in-javascript/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/kennymkchan","download_url":"https://codeload.github.com/kennymkchan/interview-questions-in-javascript/tar.gz/refs/heads/master","host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":244016794,"owners_count":20384206,"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":["array","interview-practice","interview-questions","interviews","javascript","recursion","stack","strings"],"created_at":"2024-07-31T02:01:14.991Z","updated_at":"2025-03-17T10:32:23.903Z","avatar_url":"https://github.com/kennymkchan.png","language":null,"readme":"# Interview Algorithm Questions in Javascript() {...}\n*A mostly reasonable collection of technical software development interview questions solved in Javascript in ES5 and ES6*\n\n## Table of Contents\n1. [Array](#array)\n1. [Strings](#strings)\n1. [Stacks and Queues](#stacks-and-queues)\n1. [Recursion](#recursion)\n1. [Numbers](#numbers)\n1. [Javascript Specific](#javascript)\n1. To Be Continued\n\n## Array\n\u003ca name=\"array--product\"\u003e\u003c/a\u003e\u003ca name=\"1.1\"\u003e\u003c/a\u003e\n- **[1.1](#array--product) Given an array of integers, find the largest product yielded from three of the integers**\n  ```javascript\n  var unsortedArray = [-10, 7, 29, 30, 5, -10, -70];\n\n  computeProduct(unsortedArray); // 21000\n\n  function sortIntegers(a, b) {\n    return a - b;\n  }\n\n  // Greatest product is either (min1 * min2 * max1 || max1 * max2 * max3)\n  function computeProduct(unsorted) {\n    var sortedArray = unsorted.sort(sortIntegers),\n      product1 = 1,\n      product2 = 1,\n      array_n_element = sortedArray.length - 1;\n\n    // Get the product of three largest integers in sorted array\n    for (var x = array_n_element; x \u003e array_n_element - 3; x--) {\n        product1 = product1 * sortedArray[x];\n    }\n\n    product2 = sortedArray[0] * sortedArray[1] * sortedArray[array_n_element];\n\n    if (product1 \u003e product2) return product1;\n\n    return product2;\n  }\n  ```\n  **View on Codepen:** https://codepen.io/kennymkchan/pen/LxoMvm?editors=0012\n\n\u003ca name=\"array--consecutive--sum\"\u003e\u003c/a\u003e\u003ca name=\"1.2\"\u003e\u003c/a\u003e\n- **[1.2](#array--consecutive--sum) Being told that an unsorted array contains (n - 1) of n consecutive numbers (where the bounds are defined), find the missing number in `O(n)` time**\n  ```javascript\n  // The output of the function should be 8\n  var arrayOfIntegers = [2, 5, 1, 4, 9, 6, 3, 7];\n  var upperBound = 9;\n  var lowerBound = 1;\n\n  findMissingNumber(arrayOfIntegers, upperBound, lowerBound); // 8\n\n  function findMissingNumber(arrayOfIntegers, upperBound, lowerBound) {\n    // Iterate through array to find the sum of the numbers\n    var sumOfIntegers = 0;\n    for (var i = 0; i \u003c arrayOfIntegers.length; i++) {\n      sumOfIntegers += arrayOfIntegers[i];\n    }\n\n    // Find theoretical sum of the consecutive numbers using a variation of Gauss Sum.\n    // Formula: [(N * (N + 1)) / 2] - [(M * (M - 1)) / 2];\n    // N is the upper bound and M is the lower bound\n\n    upperLimitSum = (upperBound * (upperBound + 1)) / 2;\n    lowerLimitSum = (lowerBound * (lowerBound - 1)) / 2;\n\n    theoreticalSum = upperLimitSum - lowerLimitSum;\n\n    return theoreticalSum - sumOfIntegers;\n  }\n  ```\n  **View on Codepen:** http://codepen.io/kennymkchan/pen/rjgoXw?editors=0012\n\n\u003ca name=\"array--unique\"\u003e\u003c/a\u003e\u003ca name=\"1.3\"\u003e\u003c/a\u003e\n- **[1.3](#array--unique) Removing duplicates of an array and returning an array of only unique elements**\n  ```javascript\n  // ES6 Implementation\n  var array = [1, 2, 3, 5, 1, 5, 9, 1, 2, 8];\n\n  Array.from(new Set(array)); // [1, 2, 3, 5, 9, 8]\n\n  // ES5 Implementation\n  var array = [1, 2, 3, 5, 1, 5, 9, 1, 2, 8];\n\n  uniqueArray(array); // [1, 2, 3, 5, 9, 8]\n\n  function uniqueArray(array) {\n    var hashmap = {};\n    var unique = [];\n\n    for(var i = 0; i \u003c array.length; i++) {\n      // If key returns undefined (unique), it is evaluated as false.\n      if(!hashmap.hasOwnProperty(array[i])) {\n        hashmap[array[i]] = 1;\n        unique.push(array[i]);\n      }\n    }\n\n    return unique;\n  }\n  ```\n  **View on Codepen:** http://codepen.io/kennymkchan/pen/ZLNwze?editors=0012\n\n\u003ca name=\"array--largest-difference\"\u003e\u003c/a\u003e\u003ca name=\"1.4\"\u003e\u003c/a\u003e\n- **[1.4](#array--largest-difference) Given an array of integers, find the largest difference between two elements such that the element of lesser value must come before the greater element**\n  ```javascript\n  var array = [7, 8, 4, 9, 9, 15, 3, 1, 10];\n  // [7, 8, 4, 9, 9, 15, 3, 1, 10] would return `11` based on the difference between `4` and `15`\n  // Notice: It is not `14` from the difference between `15` and `1` because 15 comes before 1.\n\n  findLargestDifference(array);\n\n  function findLargestDifference(array) {\n    // If there is only one element, there is no difference\n    if (array.length \u003c= 1) return -1;\n\n    // currentMin will keep track of the current lowest\n    var currentMin = array[0];\n    var currentMaxDifference = 0;\n\n    // We will iterate through the array and keep track of the current max difference\n    // If we find a greater max difference, we will set the current max difference to that variable\n    // Keep track of the current min as we iterate through the array, since we know the greatest\n    // difference is yield from `largest value in future` - `smallest value before it`\n\n    for (var i = 1; i \u003c array.length; i++) {\n      if (array[i] \u003e currentMin \u0026\u0026 (array[i] - currentMin \u003e currentMaxDifference)) {\n        currentMaxDifference = array[i] - currentMin;\n      } else if (array[i] \u003c= currentMin) {\n        currentMin = array[i];\n      }\n    }\n\n    // If negative or 0, there is no largest difference\n    if (currentMaxDifference \u003c= 0) return -1;\n\n    return currentMaxDifference;\n  }\n  ```\n  **View on Codepen:** http://codepen.io/kennymkchan/pen/MJdLWJ?editors=0012\n\n\u003ca name=\"array--product-other-than-itself\"\u003e\u003c/a\u003e\u003ca name=\"1.5\"\u003e\u003c/a\u003e\n- **[1.5](#array--product-other-than-itself) Given an array of integers, return an output array such that output[i] is equal to the product of all the elements in the array other than itself. (Solve this in O(n) without division)**\n  ```javascript\n  var firstArray = [2, 2, 4, 1];\n  var secondArray = [0, 0, 0, 2];\n  var thirdArray = [-2, -2, -3, 2];\n\n  productExceptSelf(firstArray); // [8, 8, 4, 16]\n  productExceptSelf(secondArray); // [0, 0, 0, 0]\n  productExceptSelf(thirdArray); // [12, 12, 8, -12]\n\n  function productExceptSelf(numArray) {\n  \tvar product = 1;\n  \tvar size = numArray.length;\n  \tvar output = [];\n\n    // From first array: [1, 2, 4, 16]\n    // The last number in this case is already in the right spot (allows for us)\n    // to just multiply by 1 in the next step.\n    // This step essentially gets the product to the left of the index at index + 1\n  \tfor (var x = 0; x \u003c size; x++) {\n  \t\toutput.push(product);\n  \t\tproduct = product * numArray[x];\n  \t}\n\n    // From the back, we multiply the current output element (which represents the product\n    // on the left of the index, and multiplies it by the product on the right of the element)\n  \tvar product = 1;\n  \tfor (var i = size - 1; i \u003e -1; i--) {\n  \t\toutput[i] = output[i] * product;\n  \t\tproduct = product * numArray[i];\n  \t}\n\n    return output;\n  }\n  ```\n  **View on Codepen:** http://codepen.io/kennymkchan/pen/OWYdJK?editors=0012\n\n\u003ca name=\"array--intersection\"\u003e\u003c/a\u003e\u003ca name=\"1.6\"\u003e\u003c/a\u003e\n- **[1.6](#array--intersection) Find the intersection of two arrays. An intersection would be the common elements that exists within both arrays. In this case, these elements should be unique!**\n  ```javascript\n  var firstArray = [2, 2, 4, 1];\n  var secondArray = [1, 2, 0, 2];\n\n  intersection(firstArray, secondArray); // [2, 1]\n\n  function intersection(firstArray, secondArray) {\n    // The logic here is to create a hashmap with the elements of the firstArray as the keys.\n    // After that, you can use the hashmap's O(1) look up time to check if the element exists in the hash\n    // If it does exist, add that element to the new array.\n\n    var hashmap = {};\n    var intersectionArray = [];\n\n    firstArray.forEach(function(element) {\n      hashmap[element] = 1;\n    });\n\n    // Since we only want to push unique elements in our case... we can implement a counter to keep track of what we already added\n    secondArray.forEach(function(element) {\n      if (hashmap[element] === 1) {\n        intersectionArray.push(element);\n        hashmap[element]++;\n      }\n    });\n\n    return intersectionArray;\n\n    // Time complexity O(n), Space complexity O(n)\n  }\n  ```\n  **View on Codepen:** http://codepen.io/kennymkchan/pen/vgwbEb?editors=0012\n\n**[⬆ back to top](#table-of-contents)**\n\n## Strings\n\u003ca name=\"string--reverse\"\u003e\u003c/a\u003e\u003ca name=\"2.1\"\u003e\u003c/a\u003e\n- **[2.1](#string--reverse) Given a string, reverse each word in the sentence**\n  `\"Welcome to this Javascript Guide!\"` should be become `\"emocleW ot siht tpircsavaJ !ediuG\"`\n  ```javascript\n  var string = \"Welcome to this Javascript Guide!\";\n\n  // Output becomes !ediuG tpircsavaJ siht ot emocleW\n  var reverseEntireSentence = reverseBySeparator(string, \"\");\n\n  // Output becomes emocleW ot siht tpircsavaJ !ediuG\n  var reverseEachWord = reverseBySeparator(reverseEntireSentence, \" \");\n\n  function reverseBySeparator(string, separator) {\n    return string.split(separator).reverse().join(separator);\n  }\n  ```\n  **View on Codepen:** http://codepen.io/kennymkchan/pen/VPOONZ?editors=0012\n\n\u003ca name=\"string--anagram\"\u003e\u003c/a\u003e\u003ca name=\"2.2\"\u003e\u003c/a\u003e\n- **[2.2](#string--anagram) Given two strings, return true if they are anagrams of one another**\n  `\"Mary\" is an anagram of \"Army\"`\n  ```javascript\n  var firstWord = \"Mary\";\n  var secondWord = \"Army\";\n\n  isAnagram(firstWord, secondWord); // true\n\n  function isAnagram(first, second) {\n    // For case insensitivity, change both words to lowercase.\n    var a = first.toLowerCase();\n    var b = second.toLowerCase();\n\n    // Sort the strings, and join the resulting array to a string. Compare the results\n    a = a.split(\"\").sort().join(\"\");\n    b = b.split(\"\").sort().join(\"\");\n\n    return a === b;\n  }\n  ```\n  **View on Codepen:** http://codepen.io/kennymkchan/pen/NdVVVj?editors=0012\n\n\u003ca name=\"string--palindrome\"\u003e\u003c/a\u003e\u003ca name=\"2.3\"\u003e\u003c/a\u003e\n- **[2.3](#string--palindrome) Check if a given string is a palindrome**\n  `\"racecar\" is a palindrome. \"race car\" should also be considered a palindrome. Case sensitivity should be taken into account`\n  ```javascript\n  isPalindrome(\"racecar\"); // true\n  isPalindrome(\"race Car\"); // true\n\n  function isPalindrome(word) {\n    // Replace all non-letter chars with \"\" and change to lowercase\n    var lettersOnly = word.toLowerCase().replace(/\\s/g, \"\");\n\n    // Compare the string with the reversed version of the string\n    return lettersOnly === lettersOnly.split(\"\").reverse().join(\"\");\n  }\n  ```\n  **View on Codepen:** http://codepen.io/kennymkchan/pen/xgNNNB?editors=0012\n\n\u003ca name=\"string--isIsomorphic\"\u003e\u003c/a\u003e\u003ca name=\"2.3\"\u003e\u003c/a\u003e\n- **[2.3](#string--palindrome) Check if a given string is a isomorphic**\n\n  ```\n  For two strings to be isomorphic, all occurrences of a character in string A can be replaced with another character\n  to get string B. The order of the characters must be preserved. There must be one-to-one mapping for ever char of\n  string A to every char of string B.\n\n  `paper` and `title` would return true.\n  `egg` and `sad` would return false.\n  `dgg` and `add` would return true.\n  ```\n  ```javascript\n  isIsomorphic(\"egg\", 'add'); // true\n  isIsomorphic(\"paper\", 'title'); // true\n  isIsomorphic(\"kick\", 'side'); // false\n\n  function isIsomorphic(firstString, secondString) {\n\n    // Check if the same lenght. If not, they cannot be isomorphic\n    if (firstString.length !== secondString.length) return false\n\n    var letterMap = {};\n\n    for (var i = 0; i \u003c firstString.length; i++) {\n      var letterA = firstString[i],\n          letterB = secondString[i];\n\n      // If the letter does not exist, create a map and map it to the value\n      // of the second letter\n      if (letterMap[letterA] === undefined) {\n        // If letterB has already been added to letterMap, then we can say: they are not isomorphic.\n        if(secondString.indexOf(letterB) \u003c i){\n            return false;\n        } else {\n            letterMap[letterA] = letterB;            \n        }\n      } else if (letterMap[letterA] !== letterB) {\n        // Eles if letterA already exists in the map, but it does not map to\n        // letterB, that means that A is mapping to more than one letter.\n        return false;\n      }\n    }\n    // If after iterating through and conditions are satisfied, return true.\n    // They are isomorphic\n    return true;\n  }\n  ```\n  **View on Codepen:** http://codepen.io/kennymkchan/pen/mRZgaj?editors=0012\n\n**[⬆ back to top](#table-of-contents)**\n\n## Stacks and Queues\n\n\u003ca name=\"stack-queue--stack-as-queue\"\u003e\u003c/a\u003e\u003ca name=\"3.1\"\u003e\u003c/a\u003e\n- **[3.1](#stack-queue--stack-as-queue) Implement enqueue and dequeue using only two stacks**\n  ```javascript\n  var inputStack = []; // First stack\n  var outputStack = []; // Second stack\n\n  // For enqueue, just push the item into the first stack\n  function enqueue(stackInput, item) {\n    return stackInput.push(item);\n  }\n\n  function dequeue(stackInput, stackOutput) {\n    // Reverse the stack such that the first element of the output stack is the\n    // last element of the input stack. After that, pop the top of the output to\n    // get the first element that was ever pushed into the input stack\n    if (stackOutput.length \u003c= 0) {\n      while(stackInput.length \u003e 0) {\n        var elementToOutput = stackInput.pop();\n        stackOutput.push(elementToOutput);\n      }\n    }\n\n    return stackOutput.pop();\n  }\n  ```\n  **View on Codepen:** http://codepen.io/kennymkchan/pen/mRYYZV?editors=0012\n\n\u003ca name=\"stack-queue--parentheses-balancing\"\u003e\u003c/a\u003e\u003ca name=\"3.2\"\u003e\u003c/a\u003e\n- **[3.2](#stack-queue--parentheses-balancing) Create a function that will evaluate if a given expression has balanced parentheses -- Using stacks**\n  In this example, we will only consider \"{}\" as valid parentheses\n  `{}{}` would be considered balancing. `{{{}}` is not balanced\n  ```javascript\n  var expression = \"{{}}{}{}\"\n  var expressionFalse = \"{}{{}\";\n\n  isBalanced(expression); // true\n  isBalanced(expressionFalse); // false\n  isBalanced(\"\"); // true\n\n  function isBalanced(expression) {\n    var checkString = expression;\n    var stack = [];\n\n    // If empty, parentheses are technically balanced\n    if (checkString.length \u003c= 0) return true;\n\n    for (var i = 0; i \u003c checkString.length; i++) {\n      if(checkString[i] === '{') {\n        stack.push(checkString[i]);\n      } else if (checkString[i] === '}') {\n        // Pop on an empty array is undefined\n        if (stack.length \u003e 0) {\n          stack.pop();\n        } else {\n          return false;\n        }\n      }\n    }\n\n    // If the array is not empty, it is not balanced\n    if (stack.pop()) return false;\n    return true;\n  }\n  ```\n  **View on Codepen:** http://codepen.io/kennymkchan/pen/egaawj?editors=0012\n\n**[⬆ back to top](#table-of-contents)**\n\n## Recursion\n\u003ca name=\"recursion--decimal-to-binary\"\u003e\u003c/a\u003e\u003ca name=\"4.1\"\u003e\u003c/a\u003e\n- **[4.1](#recursion--decimal-to-binary) Write a recursive function that returns the binary string of a given decimal number**\n  Given `4` as the decimal input, the function should return `100`\n\n  ```javascript\n  decimalToBinary(3); // 11\n  decimalToBinary(8); // 1000\n  decimalToBinary(1000); // 1111101000\n\n  function decimalToBinary(digit) {\n    if(digit \u003e= 1) {\n      // If digit is not divisible by 2 then recursively return proceeding\n      // binary of the digit minus 1, 1 is added for the leftover 1 digit\n      if (digit % 2) {\n        return decimalToBinary((digit - 1) / 2) + 1;\n      } else {\n        // Recursively return proceeding binary digits\n        return decimalToBinary(digit / 2) + 0;\n      }\n    } else {\n      // Exit condition\n      return '';\n    }\n  }\n  ```\n  **View on Codepen:** http://codepen.io/kennymkchan/pen/OWYYKb?editors=0012\n\n\u003ca name=\"recursion--binary-search\"\u003e\u003c/a\u003e\u003ca name=\"4.2\"\u003e\u003c/a\u003e\n- **[4.2](#recursion--binary-search) Write a recursive function that performs a binary search**\n\n  ```javascript\n  function recursiveBinarySearch(array, value, leftPosition, rightPosition) {\n    // Value DNE\n    if (leftPosition \u003e rightPosition) return -1;\n\n    var middlePivot = Math.floor((leftPosition + rightPosition) / 2);\n    if (array[middlePivot] === value) {\n      return middlePivot;\n    } else if (array[middlePivot] \u003e value) {\n      return recursiveBinarySearch(array, value, leftPosition, middlePivot - 1);\n    } else {\n      return recursiveBinarySearch(array, value, middlePivot + 1, rightPosition);\n    }\n  }\n  ```\n  **View on Codepen:** http://codepen.io/kennymkchan/pen/ygWWmK?editors=0012\n\n**[⬆ back to top](#table-of-contents)**\n\n## Numbers\n\u003ca name=\"numbers--power-of-two\"\u003e\u003c/a\u003e\u003ca name=\"5.1\"\u003e\u003c/a\u003e\n- **[5.1](#numbers--power-of-two) Given an integer, determine if it is a power of 2. If so,\n  return that number, else return -1. (0 is not a power of two)**\n  ```javascript\n  isPowerOfTwo(4); // true\n  isPowerOfTwo(64); // true\n  isPowerOfTwo(1); // true\n  isPowerOfTwo(0); // false\n  isPowerOfTwo(-1); // false\n\n  // For the non-zero case:\n  function isPowerOfTwo(number) {\n    // `\u0026` uses the bitwise n.\n    // In the case of number = 4; the expression would be identical to:\n    // `return (4 \u0026 3 === 0)`\n    // In bitwise, 4 is 100, and 3 is 011. Using \u0026, if two values at the same\n    // spot is 1, then result is 1, else 0. In this case, it would return 000,\n    // and thus, 4 satisfies are expression.\n    // In turn, if the expression is `return (5 \u0026 4 === 0)`, it would be false\n    // since it returns 101 \u0026 100 = 100 (NOT === 0)\n\n    return number \u0026 (number - 1) === 0;\n  }\n\n  // For zero-case:\n  function isPowerOfTwoZeroCase(number) {\n    return (number !== 0) \u0026\u0026 ((number \u0026 (number - 1)) === 0);\n  }\n  ```\n  **View on Codepen:** http://codepen.io/kennymkchan/pen/qRGGeG?editors=0012\n\n**[⬆ back to top](#table-of-contents)**\n\n## Javascript\n\u003ca name=\"javascript--hoisting\"\u003e\u003c/a\u003e\u003ca name=\"6.1\"\u003e\u003c/a\u003e\n- **[6.1](#javascript--hosting) Explain what is hoisting in Javascript**\n\n  ```\n  Hoisting is the concept in which Javascript, by default, moves all declarations to the top\n  of the current scope. As such, a variable can be used before it has been declared. Note that\n  Javascript only hoists declarations and not initializations\n  ```\n\n\u003ca name=\"javascript--use-strict\"\u003e\u003c/a\u003e\u003ca name=\"6.2\"\u003e\u003c/a\u003e\n- **[6.2](#javascript--use-strict) Describe the functionality of the `use strict;` directive**\n  ```\n  the `use strict` directive defines that the Javascript should be executed in `strict mode`.\n  One major benefit that strict mode provides is that it prevents developers from using\n  undeclared variables. Older versions of javascript would ignore this directive declaration\n  ```\n\n  ```javascript\n  // Example of strict mode\n  \"use strict\";\n\n  catchThemAll();\n  function catchThemAll() {\n    x = 3.14; // Error will be thrown\n    return x * x;\n  }\n  ```\n\u003ca name=\"javascript--event-bubbling\"\u003e\u003c/a\u003e\u003ca name=\"6.3\"\u003e\u003c/a\u003e\n- **[6.3](#javascript--event-bubbling) Explain `event bubbling` and how one may prevent it**\n  ```\n  Event bubbling is the concept in which an event triggers at the deepest possible element,\n  and triggers on parent elements in nesting order. As a result, when clicking on a child element\n  one may exhibit the handler of the parent activating.\n\n  One way to prevent event bubbling is using `event.stopPropagation()` or `event.cancelBubble`\n  on IE \u003c 9\n  ```\n\u003ca name=\"javascript--strict-operators\"\u003e\u003c/a\u003e\u003ca name=\"6.4\"\u003e\u003c/a\u003e\n- **[6.4](#javascript--strict-operators) What is the difference between `==` and `===` in JS?**\n  ```\n  `===` is known as a strict operator. The key difference between `==` and `===` is that the\n  strict operator matches for both value and type, as opposed to just the value.\n  ```\n\n  ```javascript\n  // Example of comparators\n  0 == false; // true\n  0 === false; // false\n\n  2 == '2'; // true\n  2 === '2'; // false\n  ```\n\n\u003ca name=\"javascript--null-undefined\"\u003e\u003c/a\u003e\u003ca name=\"6.5\"\u003e\u003c/a\u003e\n- **[6.5](#javascript--null-undefined) What is the difference between `null` and `undefined`**\n\n  ```\n  In Javascript, null is an assignment value, and can be assigned to a variable representing that\n  it has no value. Undefined, on the other hand, represents that a variable has been declared but\n  there is no value associated with it\n  ```\n\n\u003ca name=\"javascript--difference-inheritance\"\u003e\u003c/a\u003e\u003ca name=\"6.6\"\u003e\u003c/a\u003e\n- **[6.6](#javascript--difference-inheritance) How does `prototypal inheritance` differ from `classical inheritance`**\n\n  ```\n  In classical inheritance, classes are immutable, may or may not support multiple\n  inheritance, and may contain interfaces, final classes, and abstract classes. In contrast,\n  prototypes are much more flexible in the sense that they may be mutable or immutable. The object\n  may inherit from multiple prototypes, and only contains objects.\n  ```\n\n**[⬆ back to top](#table-of-contents)**\n","funding_links":[],"categories":["Others","Uncategorized","Github Repositories with large collections of problems-and-solutions of them most popular Interview challenges",":gem: JavaScript [Link](https://github.com/JaeYeopHan/Interview_Question_for_Beginner/tree/master/JavaScript)"],"sub_categories":["Uncategorized","[회사에 궁금한 점이 있으신가요?](https://github.com/JaeYeopHan/Interview_Question_for_Beginner/tree/master/Reverse_Interview)"],"project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fkennymkchan%2Finterview-questions-in-javascript","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Fkennymkchan%2Finterview-questions-in-javascript","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fkennymkchan%2Finterview-questions-in-javascript/lists"}