The Key Difference var is function scoped.let and const is block scoped. Letβs see what this means. Function Scope Function scope means if we declare a variable with the var keyword then the variable is accessible for the lifetime of the function inside the entire function in which it is declared. Example: function test() { …
Tag Archives: Coding Interview
Flatten an array in javascript
Learn how to convert a multi-dimensional array into single dimension array in javascript We can flatten an array to single dimension array using Array.flat(depth) method. But if we have multi-dimensional array then we need to find the depth of the Array, instead of finding depth we can solve the problem in two ways we can …
Removing space in string in Javascript
Learn how to remove space in string. If you want to remove all the space in the string thenΒ , you can use replace method var name = “Javascript jeep “; name.replace(/s/g,”); // Javascriptjeep s –> spaceg –> replace globally We can also replace the space with ‘-‘ var name = “Javascript jeep “; name.replace(/s/g,’-‘); // …
Implement copy-on-click using JavaScript
We have seen many websites have the option to copy a block of text by clicking a button. Letβs learn how to build this using vanilla JavaScript. Steps to copy text in javascript 1. Create a textarea element 2. Get the text from the div using div.innerText 3. Set the value of textarea with the …