interview Flashcards
What is DOM in JavaScript?
JavaScript can access all the elements in a web page using the Document Object Model (DOM). The web browser creates a DOM of the webpage when the page is loaded.
How to use DOM and Events?
Using DOM, JavaScript can perform multiple tasks. It can create new elements and attributes, change the existing elements and attributes and even remove existing elements and attributes. JavaScript can also react to existing events and create new events in the page.
What is Loop Though the Properties of an Object?
The for/in a loop is usually used to loop through the properties of an object. You can give any name for the variable, but the object’s name should be the same as an already existing object you need to loop through.
How to use Loops in Javascript?
for loop
Statement1 is executed first, even before executing the looping code. So, this statement is normally used to assign values to variables used inside the loop.
The statement2 is the condition to execute the loop.
The statement3 is executed every time after the looping code is executed.
for/in a loop (explained later)
The for/in a loop is usually used to loop through the properties of an object. You can give any name for the variable, but the object’s name should be the same as an already existing object you need to loop through.
while loop
The “while loop” is executed as long as the specified condition is true. Inside the while loop, you should include the statement that will end the loop at some point in time. Otherwise, your loop will never end, and your browser may crash.
do…while loop
The do…while loop is very similar to the while loop. The only difference is that in do…while loop, the block of code gets executed once even before checking the condition.
How to use Loop in JavaScript?
Loops are useful when you repeatedly execute the same lines of code a specific number of times or as long as a specific condition is true. Suppose you want to type a ‘Hello’ message 100 times on your webpage. Of course, you will have to copy and paste the same line 100 times. Instead, if you use loops, you can complete this task in just 3 or 4 lines.
How are JavaScript and ECMA Script related?
ECMA Script is like rules and guidelines, while Javascript is a scripting language used for web development.
Why you should not use innerHTML in JavaScript?
innerHTML content is refreshed every time and thus is slower.
//
Textcontent is faster
What is the unshift() method?
This method is functional at the starting of the array, unlike the push(). It adds the desired number of elements to the top of an array
What are the decodeURI() and encodeURI()?
EncodeURl() is used to convert URL into their hex coding. And DecodeURI() is used to convert the encoded URL back to normal.
Write about the errors shown in JavaScript?
Load-time errors - errors shown at the time of the page loading
Runtime errors - error that comes up while the program is running.
Logic errors - infinite loops
How are event handlers utilized in JavaScript?
Events are the actions that result from activities, such as clicking a link or filling a form by the user
What boolean operators can be used in JavaScript?
The ‘And’ Operator (&&), ‘Or’ Operator (||), and the ‘Not’ Operator (!) can be used in JavaScript
What is event bubbling?
JavaScript allows DOM elements to be nested inside each other. In such a case, if the handler of the child is clicked, the handler of the parent will also work as if it were clicked too.
What is the difference between .call() and .apply()?
.call() is used when the number of the function’s arguments are known to the programmer,
person.fullName.call(person1, “Oslo”, “Norway”);
apply() method accepts arguments in an array:
person.fullName.apply(person1, [“Oslo”, “Norway”]);
What are the important properties of an anonymous function in JavaScript?
A function that is declared without any named identifier is known as an anonymous function. In general, an anonymous function is inaccessible after its declaration.