Skip to content
Related Articles
Open in App
Not now

Related Articles

JavaScript Interview Questions and Answers | Set-2

Improve Article
Save Article
  • Difficulty Level : Easy
  • Last Updated : 05 Nov, 2019
Improve Article
Save Article

    We have already discussed some questions in JavaScript Interview Questions and Answers | Set-1 . Below are some more related questions:

  1. What are all the looping structures in JavaScript ?
    • while loop: A while loop is a control flow statement that allows code to be executed repeatedly based on a given Boolean condition. The while loop can be thought of as a repeating if statement.
    • for loop: A for loop provides a concise way of writing the loop structure. Unlike a while loop, for statement consumes the initialization, condition and increment/decrement in one line thereby providing a shorter, easy to debug structure of looping.
    • do while: A do-while loop is similar to while loop with the only difference that it checks the condition after executing the statements, and therefore is an example of Exit Control Loop.

  3. How can style/class of an element be changed ?
    To change the style/class of an element there are two possible ways.

    • document.getElementById("myText").style.fontSize = "16px;
    • document.getElementById("myText").className = "class";

  5. Explain how to read and write a file using JavaScript ?
    • The readFile() functions is used for reading operation.
      readFile( Path, Options, Callback)
    • The writeFile() functions is used for writing operation.
      writeFile( Path, Data, Callback)

  7. What is called Variable typing in JavaScript ?
    The variable typing is the type of variable used to store a number and using that same variable to assign a “string”.

    Geeks = 42;
    Geeks = "GeeksforGeeks";

  9. How to convert the string of any base to integer in JavaScript ?
    In JavaScript, parseInt() function is used to convert the string to an integer. This function returns an integer of base which is specified in second argument of parseInt() function. The parseInt() function returns Nan (not a number) when the string doesn’t contain number.

  11. Explain how to detect the operating system on the client machine ?
    To detect the operating system on the client machine, one can simply use navigator.appVersion or navigator.userAgent property. The Navigator appVersion property is a read-only property and it returns the string that represents the version information of the browser.

  13. What are the types of Pop up boxes available in JavaScript ?
    There are three types of pop boxes available in JavaScript.

    • Alert
    • Confirm
    • Prompt

  15. What is the difference between an alert box and a confirmation box ?
    An alert box will display only one button which is the OK button. It is used to inform the user about the agreement has to agree. But a Confirmation box displays two buttons OK and cancel, where the user can decide to agree or not.

  17. What is the disadvantage of using innerHTML in JavaScript ?
    There are lots of disadvantages of using the innerHTML in JavaScript like the content will replace everywhere. If you use += like “innerHTML = innerHTML + ‘html'” still the old content is replaced by HTML. It preserves event handlers attached to any DOM elements.

  19. What is the use of void(0) ?
    The void(0) is used to call another method without refreshing the page during the calling time parameter “zero” will be passed.

  21. What are JavaScript Cookies ?
    Cookies are small files that are stored on a user’s computer. They are used to hold a modest amount of data specific to a particular client and website and can be accessed either by the web server or by the client computer. When cookies were invented, they were basically little documents containing information about you and your preferences. For instance, when you select your language in which you want to view your website, the website would save the information in a document called a cookie on your computer, and the next time when you visit the website, it would be able to read a cookie saved earlier.

  23. How to create a cookie using JavaScript ?
    To create a cookie by using JavaScript you just need to assign a string value to the document.cookie object.

    document.cookie = "key1 = value1; key2 = value2; expires = date";

  25. How to read a cookie using JavaScript ?
    The value of the document.cookie is used to create a cookie. Whenever you want to access the cookie you can use the string. The document.cookie string keep a list of name = value pairs separated by semicolons, where name is the name of a cookie and the value is its string value.

  27. How to delete a cookie using JavaScript ?
    Deleting cookie is much easier than creating or reading a cookie, you just need to set the expires = “past time” and make sure one thing defines the right cookie path unless few will not allow you to delete the cookie.

  29. What are escape characters and escape() function ?
    • Escape character: This character is required when you want to work with some special characters like single and double quotes, apostrophes and ampersands. All the special character plays an important role in JavaScript, to ignore that or to print that special character, you can use the escape character backslash “\”. It will normally ignores and behave like a normal character.
      // Need escape character
      document.write("GeeksforGeeks: A Computer Science Portal "for Geeks" ")
      document.write("GeeksforGeeks: A Computer Science Portal \"for Geeks\" ")
    • escape() function: The escape() function takes a string as a parameter and encodes it so that it can be transmitted to any computer in any network which supports ASCII characters.

  31. Whether JavaScript has a concept level scope ?
    JavaScript is not concept level scope, its declared the variable inside any function has scope inside the function.

  33. How generic objects can be created in JavaScript ?
    To create a generic object in JavaScript use

    var I = new object();

  35. Which keywords are used to handle exceptions ?
    When executing JavaScript code, errors will almost definitely occur. These errors can occur due to the fault from the programmer’s side due to the wrong input or even if there is a problem with the logic of the program. But all errors can be solved by using the below commands.

    • The try statement lets you test a block of code to check for errors.
    • The catch statement lets you handle the error if any are present.
    • The throw statement lets you make your own errors.

  37. What is the use of the blur function ?
    It is used to remove focus from the selected element. This method starts the blur event or it can be attached a function to run when a blur event occurs.

  39. What is the unshift method in JavaScript ?
    It is used to insert elements in the front of an array. It is like a push method that insert elements at the beginning of the array.

My Personal Notes arrow_drop_up
Related Articles

Start Your Coding Journey Now!