Training of comparative and Boolean operators in JavaScript
6 minute(s) read
|
Published on: Jun 04, 2021
Updated on: Dec 14, 2021
|
Each of the programming languages has different features, and programmers can use each of them to create better content, but first, you have to learn them as good as possible, a good content, as you know, can attract more users, and ultimately, if you have created a site or program through the features available in different languages, you can get a high ranking on the search results page, so that you can achieve such as soon as possible due to the fact that attracting users to the website is one of the factors of success.
One of the most popular programming languages is JavaScript, which, like all existing languages, has various features; in this article, we will discuss the training of comparative and Boolean operators.
What is JavaScript?
It is one of the programming languages that can be used to implement various features and finally can help the user to interact better with the created content.
Comparison:
As the name implies, if you want to compare variables as well as existing values, you can use this to determine if there are similarities or differences between variables and existing values, simply put, you can use it to determine whether the comparison you made is true or false, if you want to make any of the following comparisons, you must use the appropriate operators to do so, which are mentioned below.
- In order to compare whether the two values are equal or not, you must use ==, but it should be noted that in this case, only the value is compared, and the equality or inequality of the type is not considered.
- In order to check whether the value and type you want to compare with each other are equal or not, === is used.
- To see that the value that we think of it is not equal to the existing values of != Must be used.
- Inequality of type is not considered; if you want to consider inequality of type and value, you must use !==.
- To compare two values in terms of being larger or smaller than the other, you should use x> y and x - It can also be checked whether the variables are greater than or equal to each other or smaller than and equal to each other, for which the following should be used, respectively: >= & <= These operators are used for logic between variables or values; you should pay attention to the point that If you want to compare two different cases at the same time, you need to use the AND operator (&&); for better understanding, you should pay attention to the following example. The result of this coding will be as follows. The AND operator (&&) returns true if both expressions are true. Otherwise, it returns false. true false - OR operator (||) should be used to check if one or both of the comparisons that are taking place are correct. The result of this coding will be as follows. The OR operator (||) returns true if one or both expressions are true; otherwise, it returns false. false true true true - The NOT operator (!) Returns true for false statements and false for true statements. The result of this coding will be as follows. The NOT operator (!) returns true for false statements and false for true statements. true false For example, you might want to compare a string with numbers, which can have strange results; before going to the following examples, you need to know some points. - While comparing, if the number is a string, it is considered as a number. - If you want to make a comparison with an empty string, that empty string is considered zero in the comparison. - Another thing that needs to be mentioned is that if there is text inside the string, and you want to compare it with a number, a non-numeric string converts to NaN, which is always false. An example of each one is given below. The result of the example will be as follows. true The result of the example will be as follows. false The result of the example will be as follows. false In programming, this can be used to check whether a phrase is true or false, which can have two values maximally, which will be mentioned in the following. YES / NO ON / OFF TRUE / FALSE As mentioned earlier, it is used in order to find out whether the variable is correct or not. To understand better, you can use this example. The result of this example, after clicking on the Try it button, will be as follows. Display the value of Boolean (10> 9): Try it true Another example in this regard is given below. The result of this example, after clicking on the Try it button, will be as follows. Display the value of 10> 9: Try it true You can use the new keyword and finally create Boolean object. The result of which will be as follows. Never create booleans as objects. Booleans and objects cannot be safely compared. boolean object In general, in the JavaScript programming language, there are various features that can be used to help each of us perform tasks that may be complex. In this article, we have examined two of the features that exist in this language, we have suggested that through one of these, it is possible to examine the relationship between different variables in terms of quantity and type, and through Boolean, it is possible to examine the correctness or incorrectness of the phrase which this article provides you with explanations and examples in relation to both of these cases so that you can master them and get help from them to create different types of contents.Logical Operators:
Comparison
Comparison
Comparison
Comparing Different Types:
Example in relation to case number 1:
Comparison
Example in relation to case 2:
Comparison
Example in relation to case 3:
Comparison
Booleans:
Boolean ():
Boolean objects:
Last word: