FrontendDeveloper.in

JavaScript Interview Questions

  • Question 106

    What is BOM

    The 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 the window. The Browser Object Model is not standardized and can change based on different browsers.

    Screenshot

  • Question 107

    What is the use of setTimeout

    The setTimeout() method is used to call a function or evaluate an expression after a specified number of milliseconds. For example, let's log a message after 2 seconds using setTimeout method,

    setTimeout(function () {
    console.log("Good morning");
    }, 2000);
    
  • Question 108

    What is the use of setInterval

    The setInterval() method is used to call a function or evaluate an expression at specified intervals (in milliseconds). For example, let's log a message after 2 seconds using setInterval method,

    setInterval(function () {
    console.log("Good morning");
    }, 2000);
    
  • Question 109

    Why is JavaScript treated as Single threaded

    JavaScript 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.

  • Question 110

    What is an event delegation

    Event 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.

    For example, if you wanted to detect field changes inside a specific form, you can use event delegation technique,

    var form = document.querySelector("#registration-form");
    
    // Listen for changes to fields inside the form
    form.addEventListener(
    "input",
    function (event) {
    // Log the field that was changed
    console.log(event.target);
    },
    false
    );
    
  • Question 111

    What is ECMAScript

    ECMAScript is the scripting language that forms the basis of JavaScript. ECMAScript standardized by the ECMA International standards organization in the ECMA-262 and ECMA-402 specifications. The first edition of ECMAScript was released in 1997.

  • Question 112

    What is JSON

    JSON (JavaScript Object Notation) is a lightweight format that is used for data interchanging. It is based on a subset of JavaScript language in the way objects are built in JavaScript.

  • Question 113

    What are the syntax rules of JSON

    Below are the list of syntax rules of JSON

    1. The data is in name/value pairs
    2. The data is separated by commas
    3. Curly braces hold objects
    4. Square brackets hold arrays
  • Question 114

    What is the purpose JSON stringify

    When 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.

    var userJSON = { name: "John", age: 31 };
    var userString = JSON.stringify(userJSON);
    console.log(userString); //"{"name":"John","age":31}"
    
  • Question 115

    How do you parse JSON string

    When receiving the data from a web server, the data is always in a string format. But you can convert this string value to a javascript object using parse() method.

    var userString = '{"name":"John","age":31}';
    var userJSON = JSON.parse(userString);
    console.log(userJSON); // {name: "John", age: 31}
    
  • Question 116

    Why do you need JSON

    When exchanging data between a browser and a server, the data can only be text. Since JSON is text only, it can easily be sent to and from a server, and used as a data format by any programming language.

  • Question 117

    What are PWAs

    Progressive web applications (PWAs) are a type of mobile app delivered through the web, built using common web technologies including HTML, CSS and JavaScript. These PWAs are deployed to servers, accessible through URLs, and indexed by search engines.

  • Question 118

    What is the purpose of clearTimeout method

    The 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.

    For example, the below setTimeout method is used to display the message after 3 seconds. This timeout can be cleared by the clearTimeout() method.

    <script>
    var msg;
    function greeting() {
    alert('Good morning');
    }
    function start() {
    msg =setTimeout(greeting, 3000);
    
    }
    
    function stop() {
    clearTimeout(msg);
    }
    </script>
    
  • Question 119

    What is the purpose of clearInterval method

    The 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.

    For example, the below setInterval method is used to display the message for every 3 seconds. This interval can be cleared by the clearInterval() method.

    <script>
    var msg;
    function greeting() {
    alert('Good morning');
    }
    function start() {
    msg = setInterval(greeting, 3000);
    
    }
    
    function stop() {
    clearInterval(msg);
    }
    </script>
    
  • Question 120

    How do you redirect new page in javascript

    In vanilla javascript, you can redirect to a new page using the location property of window object. The syntax would be as follows,

    function redirect() {
    window.location.href = "newPage.html";
    }
    
Get LinkedIn Premium at Rs 399