Ans: To involve a JavaScript code in an HTML file, we have three ways in total. These ways are written below:
Let’s begin with the inline function. It is a JavaScript function, to a variable generated at runtime, this function is dedicated. As it is assigned to a variable, you can use it again. That’s how you can differentiate between Inline Functions and Anonymous. If you require JavaScript for a function, you can work using two methods. You can integrate the script into the page that you are building up. Another way is to put it in a separate file. In this way, you can use it whenever you want. That is the differentiation between an internal script and an external script.
Ans: Surprisingly, to define the variable in JavaScript, again you have three ways. These are briefly described in the next few lines.
Ans: In JavaScript, you don’t have to set out the information you are going to store in a variable. That is because it is a loosely typed language. JavaScript types a variable depending on the type of information you assign to it on its own. There are several languages that resemble Java, and won’t require you to specify a variable’s type like int, float, boolean, or String.
In Typed Language, the values are related to the values instead of variables. It has two types:
Ans: When we talk about local storage, the data doesn’t return to the server for every HTTP request. Consequently, the amount of traffic between client and server decreases. It is not removed till you clear via setting or program manually.
Session Storage resembles local storage in many ways. They have the same API. both f these are used to save keys or value pairs. However, there is one difference. The data stored in the local storage doesn’t expire, whereas, in session storage, data is removed when the page session ends. Session Storage will leave when the browser is closed.
Ans: “==” operator with the help of type correction compares the variables. It allows you to compare numeric information with string, etc. The “===” doesn’t allow that. That is due to the way it functions. It checks the value and the type of two variables. if two variables are unidentical “===” return false. For this operation “==” return true.
JavaScript is known to be strict. So, it's essential to understand which operator is suitable for the type of operation you want to perform. For the comparison of two variables of a different type, for example, a boolean with a string or a vice versa using == operator. In this situation, it changes one type into another automatically. And, it returns the value depending on content equality. On the other hand, if the two variables are of the same type and contain the same value, === operator returns true.
|