Free Web Development Online Tutorials, Learn to Code
JavaScript basic interview questions for freshers, Advanced JavaScript interview questions

JavaScript interview questions for freshers

Latest JavaScript Interview Questions and Answers for Beginners.

javascript Interview Questions Answers

Advanced Javascript Interview Questions

  1. What is JavaScript?
    JavaScript is a client-side Programming language, but also can be used as server side scripting language, JavaScript can be used with all web development technologies like java,, php, python etc. JavaScript can post data to serve side and external API. JavaScript is an open source and cross-platform scripting language.
  2. What are the different Data Types in JavaScript?
    • String
    • Number
    • Boolean
    • Undefined
    • Null
    • Object
  3. What is 'this' keyword in JavaScript?
    'this' keyword refers the current object from where it was being called.
  4. What is the use of isNaN function?
    isNan function returns boolean value true if the argument is not a number otherwise it is false.
  5. How to comment any code in Javascript?
    Single line comment example
    // for Single line comment
    Multi line comment example
    /* Multi 
    comments */
  6. What are the different types of loops in JavaScript?
    • For loop
    • While loop
    • do-while loop
    Learn more about loop in javascript with examples
  7. Can we access JavaScript function written in a different file? If yes then how?
    Yes, we can add access JavaScript function written in a different file by adding the file reference.
    <script src="~/Scripts/jquery.validate.js"></script>
  8. Is JavaScript a case-sensitive language?
    Yes, JavaScript is a case sensitive scripting language. So when we define any variable (like var k;), while accessing we have to use the same case, otherwise it will be considered as a different variable
        var k;
        var K; // different ;
  9. Which company developed JavaScript?
    Netscape, a software company who developed JavaScript.
  10. What is the difference between "not defined" and "undefined" in JavaScript?
    When we try to use any variable that has not been declared or doesn't exist then JavaScript will throw an error var name is not defined.
    var a; // declaring x
    console.log(a); //output: undefined 

    Now if we try to user some variable that has not been declared before

    var a; // Declaration
    console.log(b);  // Output: ReferenceError: b is not defined
  11. How to create an object in JavaScript?
    There are many different ways we can create object in JavaScript, here is a common example
    var Employee = function (name, org, salary) { = name || "";  //attribute default value is null
        this.organization = org || ""; 
        this.salary = salary || 5000; 
    var emp1 = new Employee("Bill","Microsoft",3000);
    var emp2 = new Employee("Whitney","IBM",5000);
  12. How to declare an array with some default values in JavaScript?
    Usually we always declare any array with some values assigned in it, here is how we can do
    var colors =  ['red','blue','orange','while','black','green'];
    Learn more about JavaScript Array with example
  13. How to define anonymous function in JavaScript
    This type of function has no name, anonymous can be easily declared in like an expression, starts with function keyword.
    var helloWorld = function () {
        alert("Anonymous function invoked");
    Learn more about JavaScript Function with example
  14. How to set line break to a string in JavaScript code?
    We can add line break in a string statement using a backslash '\n' , at the end of each line.
    console.log("Hello World! \n I am ready for next day!");
    // OR 
    document.write("Hello Friend! \n How are you doing?");

    In above statement line will be broken to next line wherever \n found, Make sure code is within script tag.

  15. How to write async function in javascript?

    We can write async function in javascript using async keyword.

    let checkUser = async function(username, password){
    try {
    //let result = setTimeout(() => console.log("Tick"), 500);
            console.log("Welcome "+ username);
            throw new Error("some error message");
            //return result;
        catch (ex)
  16. How to call a async function with await keyword in JavaScript?

    Look at the example below, where I am calling the above async function from below async function using await keyword.

    Notice, the line let result= await checkUser("u1","p1");
    async function myAsyncMethod() {
        try {
           let result= await checkUser("u1","p1");
        } catch (e) {
        } finally {
            console.log('we reached finally block');

    Learn more about JavaScript Async Function with example

  17. What is the difference among equal sign single = , double == and triple ===?

    Single = is used for assigning value, right to left
    Double == is for comparing the value
    Triple === is for comparing value with type

    Here are some examples.
    if (2=="2")
        console.log("2=='2' is true");
    if (2==="2")
        console.log("2==='2' is true");
        console.log("2==='2' is false");
    var bar = null;
    console.log(typeof bar === "object");
  18. How to write foreach to loop through array in JavaScript ?
    Here is an example of foreach in array
    var subjectArray = ["JavaScript", "JSON", "Asp.Net Core", "PHP"];
    function fetch(item, index) {
        console.log(index + ":" + item );

    We also can write like example below.

    subjectArray.forEach(function (fetch) {
  19. How to define an array variable in JavaScript with different type of data?

    In following student variable, we can store different type of data like name (string), age (integer) etc.

    var student= {name:"Arayan Bose",age:29, batch:"XII"};
  20. What is cookie in JavaScript? How to us cookie in JavaScript?

    Cookie is the small piece of data in plain text, each cookie contain data in name-value pair.

    In JavaScript we can access cookie object through document.cookie.

    To retrive all cookies, we can write code using document.cookie like below.

    var _cookies = document.cookie;
    document.write("All Cookies : " + _cookies);
    //To split all cookies pairs in an array.
    cookiearray = _cookies.split(';');

    document.cookie.length will get you the length of cookies.

    Write following code to create cookie in JavaScript.

    var _siteTitle = "Learn JavaScript Free";
    var _cookieValue = escape(_siteTitle) + ";";
    document.cookie = "title=" + _cookieValue;
    var _cookies = document.cookie;
    document.write("All Cookies : " + _cookies);
  21. How to change text of html button using JavaScript?

    To change any property of any html element we can access the html element either by id or by name, here in example we change the button property value accessing by id.

    Notice, the button text will become "Click Me" to "Have Fun".

    <input type="button" id="btnSave" value="Click Me!" onclick="ChangeText();" />
    <script type="text/javascript">
    	function ChangeText()
    		var btn = document.getElementById("btnSave")
    		btn.value = "Have Fun!";
Javascript Interview Questions

free javascript tutorial online
JavaScript Course Online, Check FREE JavaScript Tutorial
javascript course online
free javascript tutorial online
Interview Question Answers | Fresher Job Interview Tips