The logical operators used in Javascript are listed below:OperatorUsageDescription Logical AND ( && ) a && b is true if both a and b are true. Logical OR ( || ) a || b is true if either a or b is true. Logical NOT ( ! ) !a is true if a is not true. JavaScript ...
This chapter explains JavaScript operators in detail. It starts with the arithmetic operators and then looks at the comparison operators and logical operators that are used for formulating conditional checks in JS programs. The final section of the chapter covers the assignment and bitwise operators....
In JavaScript, the logical operators have different semantics than other C-like languages, though. They can operate on expressions ofany type, not just booleans. Also,the logical operators do not always return a boolean value, as the specification points out insection 12.12: The value produced ...
Assignment operators are used to assign values to JavaScript variables.Given that x = 10 and y = 5, the table below explains the assignment operators:OperatorExampleSame AsResult in xTry it = x = y x = y x = 5 Try it » += x += y x = x + y x = 15 Try it » -= x...
JavaScript String OperatorsThe + operator can also be used to add (concatenate) strings.When used on strings, the + operator is called the concatenation operator.Example txt1 = "John"; txt2 = "Doe"; txt3 = txt1 + " " + txt2; The result of txt3 will be: John Doe Try it ...
Comparison operators are fully described in theJS Comparisonschapter. JavaScript String Comparison All the comparison operators above can also be used on strings: Example lettext1 ="A"; lettext2 ="B"; letresult = text1 < text2; Try it Yourself » ...
var name = person && person.getName(); This code is the same as if(person) { var name = person.getName(); } The || operator is used for setting default values. var name = persons_name || "John Doe"; The equalant code is ...
JavaScript String OperatorsThe + operator, and the += operator can also be used to concatenate (add) strings.Given that t1 = "Good ", t2 = "Morning", and t3 = "", the table below explains the operators:OperExamplet1t2t3Try it + t3 = t1 + t2 "Good " "Morning" "Good Morning" ...
CopyThe void operator can also be used to specify an expression as a hypertext link. The expression is evaluated but is not loaded in place of the current document.Here is an example of using void(0) on a link:Link to perform no action. CopyThe code above creates a link that does...
(10).then(v=>{console.log(v);// prints 60 after 4 seconds.});(asyncfunction(x){// async function expression used as an IIFEvarp_a=resolveAfter2Seconds(20);varp_b=resolveAfter2Seconds(30);returnx+awaitp_a+awaitp_b;})(10).then(v=>{console.log(v);// prints 60 after 2 ...