- 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.
- 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";
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";
- 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.
- 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.
- 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.
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.
document.cookie = "key1 = value1; key2 = value2; expires = date";
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.
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.
- What are escape characters and escape() function ?
// 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.
var I = new object();
- Which keywords are used to handle exceptions ?
- 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.
- 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.
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.