Quick Contact

    Top 30 JavaScript Interview Questions and Answers

    Q1.What is JavaScript?

    JavaScript is a widely used web scripting language for both client-side and server-side programming. JavaScript code may be placed into HTML pages that web browsers can understand and execute while also enabling object-oriented programming abilities.

    Q2- Mention the various data types that exist in JavaScript?

    The following data types are supported by JavaScript:

    • Boolean –

      It is used for true and false values.

    • Null –

      It is used forempty or unknown values.

    • Undefined –

      It is used for variables that are only declared and not defined or initialized.

    • Number –

      It is used for integer and floating-point numbers.

    • String –

      It is used for characters and alphanumeric values.

    • Object –

      It is used for collections or complex values.

    • Symbols –

      It is used for unique identifiers for objects.

    Q3- What are the features of JavaScript?

    These are the features of JavaScript:

    • Lightweight, interpreted programming language
    • Cross-platform compatible
    • Open-source
    • Object-oriented
    • Integration with other backend and frontend technologies
    • Used especially for the development of network-based applications

    Q4. How do you create an object in JavaScript?

    Because JavaScript is an object-oriented programming language, its supports and encourages the utilization of objects while designing online applications.

    constemployee = {
        name: 'Robert',
        age: 17

    Q5. How do you create an array in JavaScript?

    Here’s a quick method to create arrays in JavaScript using the array literal:

    var a = [];
    var b = [‘a’, ‘b’, ‘c’, ‘d’, ‘e’];

    Q6. What are the scopes of a variable in JavaScript?

    The scope of a variables denotes where it was declared or constructed in a JavaScript application. The variables can have two scopes:

    Global Scope

    Global variables with global scope are provided throughout the JavaScript code.

    Local Scope

    Local variables can only be accessed within the function in in which they are declared.

    Q7. What is the ‘this’ keyword in JavaScript?

    In JavaScript, the ‘this’ keyword refers to the object that is now being called. It is widely used to allocate costs to object attributes in constructors.

    Q8- How do you debug a JavaScript code?

    All current web browsers, such as Chrome and Firefox, have a debugging that can be used at any time by clicking the corresponding key, which is generally the F12 key. The debugging tools provide users with a number of functions.

    We may also debug JavaScript code within the code editor that we use to build JavaScript applications, such as Visual Studio Code, Atom, Sublime Text, and so on.

    Q9. What are the ways of adding JavaScript code in an HTML file?

    There are two primary methods for integrating JavaScript code:

    • We may execute JavaScript code inside the script element of the same HTML file; this is useful when only a few lines of scripting are required for a web page.
    • We can add complete scripting features to a web page without complicating the code by importing a JavaScript source file into an HTML document.

    Q10. What do you understand about cookies?

    A cookie is a little piece of data supplied from a website and kept on the user’s system by the web browser which used visit the page. Cookies are utilized to recall the information for subsequent use as well as to record website viewing activities.

    Q11. How would you create a cookie?

    The easiest approach to make a cookie using JavaScript is as follows:

    document.cookie = “key1 = value1; key2 = value2; expires = date”;

    Q12. How would you read a cookie?

    It is also quite simple to read a cookies through JavaScript. We may utilize the document.cookie string, which includes the cookies we just created with it.

    The document.cookie string contains a list of name-value pairings distinguished by semicolons, whereby ‘name’ is the cookie’s name and ‘value’ is its value. To divide the cookie value into keys and values, we may use the split() function.

    Q13. What are the different ways an HTML element can be accessed in a JavaScript code?

    In JavaScript, an HTML element can also be accessible in the following ways:

    • getElementByClass(‘classname’):

      Returns all HTML components with the supplied classname.

    • getElementById(‘idname’):

      Retrieves an HTML element based on its ID name.

    • getElementbyTagName(‘tagname’):

      Returns all HTML components with the supplied tagname.

    • querySelector():

      Takes a CSS style selection and provides the first HTML element it finds.

    Q14. What is Document and Window in JavaScript?

    The document is part of the Windows object and may be thought of as its feature. In JavaScript, a Windows is a global object that stores structure such as parameters, operations, locations, history, and so on.

    Q15- What is NaN property in JavaScript?

    The “Not-a-Number” value is represented by the NaN attribute. It denotes a value that is not a valid number.

    A Number will be returned if typeof of NaN is used.

    The isNaN() function is used to determine whether a value is NaN.

    Q16- What do you mean by Self Invoking Functions?

    A conscience statement is automatically executed when it is not requested (initiated). When a function expression is introduced by (), it is automatically executed. A function declaration cannot be called on its own.

    Normally, we define a function and call it; however, anonymously functions can be used to dynamically run a function when it is specified and will never be called again. And these sorts of functions have no names.

    Q17. What are some advantages of using External JavaScript?

    External JavaScript comprises JavaScript Code (script) created in a specific folder with the extension.js, which is then linked inside the < head> or < body> section of the HTML file in which the programming is to be inserted.

    External javascript has the following advantages:

    1. It enables collaboration between web designers and programmers on HTML and javascript files.
    2. The code may be reused.
    3. External javascript code reading is straightforward.

    Q18- What are object prototypes?

    A prototype’s properties are passed down to all javascript objects. As an example,

    • Date entities acquire the Date prototype’s attributes.
    • Math objects acquire the Math prototype’s characteristics.
    • Properties from the Array prototype are passed down to array objects.
    • Object.prototype is at the top of the chain. Every prototype inherits the Object.prototype’s attributes and functions.
    • A prototype is an object’s blueprint. The prototype enables us to utilize attributes and methods on an object even if they do not exist on the current object.

    Q19- What are callbacks?

    A callback function is one that is performed after another function has been executed. Functions are recognized as first-class citizens in javascript; they may be sent as an assignment to some other function, produced by another function, and utilized as a parameter of an object.

    Q20- What are the types of errors in javascript?

    In javascript, there are two categories of mistakes.

    1. Syntax error:

      Syntax errors are coding errors that cause the programme to either not execute at all or to stop executing halfway through. Error messages are typically provided as well.

    2. Logical error:

      A logical error occurs when the grammar is correct but the reasoning or programme is faulty. In this situation, the programme runs without issue. However, the output results are incorrect. Because these programmes do not provide error signals for logic flaws, they might be more difficult to rectify than syntax difficulties.

    Q21. What is DOM?

    DOM is an abbreviation for Document Object Model. The Document Object Model (DOM) is a programming environment for HTML and XML documents. Whenever a browser attempts to generate an HTML page, it produces a DOM object based on the HTML document. We may edit or change various parts inside the HTML content using this DOM.

    Q22. What do you mean by BOM?

    BOM stands for Browser Object Model. Users may interact with the browser through it. A window is the first item in a browser. As a consequence, you may directly or indirectly call every one of the window’s functionalities. The window object contains the document, histories, display, navigation, location, and other characteristics.

    Q23. What is the distinction between client-side and server-side JavaScript?

    Client-side JavaScript consists of two parts: a basic language and predefined objects for executing JavaScript in a browser. The HTML pages automatically incorporate JavaScript for the client. This script is understood by the browser at runtime.

    Client-side JavaScript works in the same way as server-side JavaScript. It contains JavaScript that will run on a server. The server-side JavaScript is only deployed after processing.

    Q24. What do mean by prototype design pattern?

    The Prototype Pattern generates various things, but instead of returning uninitialized objects, it generates objects with values that are reproduced from a template – or sample – object. The Prototype pattern, also known as the Properties pattern, is used to generate prototypes.

    The introduction of business objects with parameters that correspond to the database’s default settings is an example of how the Prototype pattern may be useful. The prototype object stores the default parameters for a newly formed business entity.

    The Prototype pattern is rarely utilized in traditional languages, however it is employed in the creation of new objects and templates in JavaScript, a prototypal language.

    Q25. Why do we use callbacks?

    A callback function is a procedure that is passed as an input to another function (let’s call this other function “thisFunction”) and is executed within thisFunction once the function has finished execution.

    JavaScript is an event-driven scripting language. Instead of waiting for a response before proceeding, JavaScript will continue to function while watching for new events. Callbacks are a method of guaranteeing that one piece of code does not run until another piece of code has completed its execution.

    Q26. Difference between prototypal and classical inheritance.

    In classic OO programming, programmers create objects, which are representations of real-time entities. The two types of abstractions are classes and objects. An object is a generalization of a class, whereas a class is an abstraction of an actual entity. A Vehicle, for example, is a subset of a Car. Automobiles (class) are so descended from vehicles (object).

    Classical inheritance varies from prototypal inheritance in that it is limited to classes that inherit from the remaining classes, whereas prototypal inheritance allows any object to be cloned via an object linking technique. Regardless of whether it extends the parent object or not, a prototype effectively acts as a template for those other objects.

    Q27- What do you mean by JavaScript Design Patterns?

    JavaScript flowcharts are reproducible solutions to issues that might occur when developing JavaScript browser apps. They genuinely help us make our code more reliable.

    They are divided mainly into 3 categories

    1. Creational Design Pattern
    2. Structural Design Pattern
    3. Behavioral Design Pattern.
    • Creational Design Pattern:

      The JavaScript Creational Design Pattern addresses the object generation method. They strive to create goods that are fit for a certain setting.

    • Structural Design Pattern:

      The JavaScript Structural Design Pattern describes how we can integrate the classes and objects that we’ve created so far to build larger frameworks. This pattern facilitates the creation of connections between things by offering a simple method for doing so.

    • Behavioral Design Pattern:

      This design pattern emphasizes common patterns of communication between JavaScript objects. As a result, communication may be carried out more freely.

    Q28. What are the primitive data types in JavaScript?

    A primitive data type is one that is not made up of other data types. It can only display a single value at a time. Every primitive is, by definition, a built-in data type (the compiler must be knowledgeable of them) However, not all of the built-in datasets are primitives. There are five main types of fundamental data in JavaScript. There are the following values available:

    1. Boolean
    2. Undefined
    3. Null
    4. Number
    5. String

    Q29. What are generator functions?

    Function* is used to declare generator functions, which are a specific class of functions and keywords. It does not run the code, but instead generates a generating object that controls the execution.

    Q30. What is the Strict mode in JavaScript?

    Strict mode in JavaScript enforces stricter error-checking in JavaScript code.

    • In Strict mode, all variables must be defined explicitly, values cannot be given to read-only properties, and so on.
    • We may enable strict mode by including ‘use strict’ at the start of a JavaScript code block or within a specific section of code.

    Copyright 1999- Ducat Creative, All rights reserved.

    Anda bisa mendapatkan server slot online resmi dan terpercaya tentu saja di sini. Sebagai salah satu provider yang menyediakan banyak pilihan permainan.