Category: Javascript Faqs
-
What’s the difference between let and var?
Both let and var are used for variable and method declarations in JavaScript. So there isn’t much of a difference between these two besides that while var keyword is scoped by function, the let keyword is scoped by a block.
-
How would you delete a cookie?
To delete a cookie, we can just set an expiration date and time. Specifying the correct path of the cookie that we want to delete is a good practice since some browsers won’t allow the deletion of cookies unless there is a clear path that tells which cookie to delete from the user’s machine. function…
-
How would you read a cookie?
Reading a cookie using JavaScript is also very simple. We can use the document.cookie string that contains the cookies that we just created using that string. The document.cookie string keeps a list of name-value pairs separated by semicolons, where ‘name’ is the name of the cookie, and ‘value’ is its value. We can also use…
-
How would you create a cookie?
The simplest way of creating a cookie using JavaScript is as below: document.cookie = “key1 = value1; key2 = value2; expires = date”;
-
What do you understand about cookies?
A cookie is generally a small data that is sent from a website and stored on the user’s machine by a web browser that was used to access the website. Cookies are used to remember information for later use and also to record the browsing activity on a website.
-
What are the ways of adding JavaScript code in an HTML file?
There are primarily two ways of embedding JavaScript code: Intermediate JavaScript Interview Questions and Answers Here are some intermediate level JavaScript interview questions and answers for you to prepare during your interviews.
-
What is the difference between Function declaration and Function expression?
Function declaration Function expression Declared as a separate statement within the main JavaScript code Created inside an expression or some other construct Can be called before the function is defined Created when the execution point reaches it; can be used only after that Offers better code readability and better code organization Used when there is…
-
How do you debug a JavaScript code?
All modern web browsers like Chrome, Firefox, etc. have an inbuilt debugger that can be accessed anytime by pressing the relevant key, usually the F12 key. There are several features available to users in the debugging tools. We can also debug a JavaScript code inside a code editor that we use to develop a JavaScript…
-
What is Callback in JavaScript?
In JavaScript, functions are objects and therefore, functions can take other functions as arguments and can also be returned by other functions. Fig: Callback function A callback is a JavaScript function that is passed to another function as an argument or a parameter. This function is to be executed whenever the function that it is passed to gets executed.
-
What are the conventions of naming a variable in JavaScript?
Following are the naming conventions for a variable in JavaScript: