JavaScript interview questions and answers | Infographic

Basic and most common JavaScript interview questions and answers. Question 1: What is closure in JavaScript? Answer: A closure is a funciton and has access to variables that are declared and defined in the parent function scope even after the outer function has returned. Question 2: What is the use of window objects in JavaScript? Read More…


How to insert variables in JavaScript string? | Example code

How to insert variables in JavaScript string? Using Template literals you can put variables inside JavaScript strings. Template literals can contain placeholders. These are indicated by the dollar sign and curly braces (${expression}). Note: from 2015 onwards, just use backticks for templating. Above code that it is a backtick, not a quote. Complete HTML example Read More…


JavaScript function optional parameter | 3 Ways Examples code

You can declare a function with optional parameter using Logical OR operator (‘||’) or Assignment operator (“=”), etc in JavaScript. JavaScript function optional parameter can do it in 3 ways:- Undefined property OR (||) operator The assignment operator (“=”) Declare optional function parameters in JavaScript Example Let’s see all method examples in HTML:- Using undefined Read More…


JavaScript static variable | Create and Use examples

First, static variables preserve their previous value in their previous scope and are not initialized again in the new scope. But JavaScript doesn’t support static variables or a direct way to create them. There is no static keywords in JavaScript. But you can implement function static variables in JavaScript and use them for purposes. JavaScript Read More…


JavaScript ternary operator without else condition | Is it possible?

How to use a ternary operator in JavaScript without else or empty? Is it possible? A ternary operation is called ternary because it takes 3 arguments, if it takes 2 it is a binary operation. It’s an expression returning a value. If you omit the else you would have an undefined situation where the expression Read More…


Calling a Function defined inside another function in JavaScript | Example

How to call a child function inside a function from another function in Javascript? Want to call the function HelloAgain() from MyFunction(). Answer: You can’t. The scope of HelloAgain is limited to the Hello function. This is the only way to make private scope in javascript. But you can use the this keyword to deal Read More…


Write a JavaScript code to add two numbers using the call back function

Generally, callback function not required for addition operation but it could use to show the result. Call the Addition (addNumber) function with a callback, and let the Addition (addNumber) function run the callback after the calculation is finished: JavaScript code to add two numbers using call back function example HTML example code: If you want Read More…


What is difference between var functionName = function vs function functionName

The difference between: var functionName = function() {} and function functionName() {} in Javascript? There are two ways of declaring functions in JS. Which are called function expression and a function declaration. The first example is a function declaration: function abc(){} The second example is a function expression: Let’s see the difference between them: function Read More…


JavaScript set to Array | Simple example code

The simplest way to convert the set to Array is just to spread the set inside square brackets [ ]. Another way convert set to Array in JavaScript:- Array.from() method Spread operator forEach Example of convert set to Array in JavaScript Let’s see the one by one HTML example code for each method:- 1. Array.from() Read More…


JavaScript remove button| Example code Simple

Use id in HTML button and removeChild method to remove button Using JavaScript. Example code remove HTML button Using JavaScript In the example we have 2 buttons: First Will remove Second will remove first button The action button will call function, where find the element by id then use removeChild method to remove button in Read More…