Boolean operator

Boolean operators are used to test the relationship between two values , There are three Boolean operators , Logic is not (!)、 Logic and (&&), Logic or (||).

Logic does not consist of an exclamation mark (!) form , It can be applied to JavaScript Any value . Logical non first converts its operands to a Boolean value , And then reverse the Boolean .

console.log(!NaN);//true
console.log(!123);//false
console.log(!"");//true
console.log("");//false
console.log(!{});//false

Logical and are represented by two sums (&&), There are two operations to do . As shown in the figure below :var result=true&&false;

The first operand

The second operand

result

True

True

True

True

False

False

False

True

False

False

False

False

It can be seen from the above table that only when the first parameter and the second parameter are both true, The result of logic and is true

Logic may consist of two vertical symbols (||), There are two operands , As shown in the figure below :var result = true||false;

The first operand

The second operand

result

True

True

True

True

False

True

False

True

True

False

False

False

It can be seen from the above table that , The result of one of the operands is true, The result of logical or is true. Both operands are false, The result is false

The multiplication operator consists of an asterisk (*) form , Used to calculate the product of two values .

var num =2*3;
console.log(num);// Output 6

The division operator consists of a slash (/) form , For the calculation of dividing the first operand by the first one .

var num=4/2;
console.log(num);// Output 2

The modulus operator consists of a percent sign (%) form , It's used to calculate the remainder .

var num=5%2;
console.log(num);// Output 1

The addition operator consists of a plus sign (+) form , Used to sum and splice strings .

var num=5+5;
var num1 = 5+"5";
console.log(num);//
console.log(num1);// First the 5 Convert to string and then splice , Output “55”

The subtraction operator consists of a minus sign (-) form ,var result=2-1.

+、- Special use of :

1. Both numbers are numerical , Then the numerical calculation of addition and subtraction is carried out directly .

2. If one of the operands is NaN, The result is NaN

3. If Infinity+(-)Infinity, The result is NaN

JavaScript The operator ( Boolean operator 、 Multiplicative operators and additive operators ) More articles about

  1. Javascript Advanced programming learning notes (5)—— JS The operator

    Don't talk much , Start today's journey of codewords . All of a sudden, I feel like a novel ,emm... The operator ECMAScript(JS The core ) Describes a set of operators for manipulating data values , It also includes arithmetic operators and so on and JS The most striking feature of these operators in is ...

  2. LeetCode The competition question : Stupid factorials ( We designed a stupid factorial clumsy: In a decreasing sequence of integers , We replace the original multiplication operator with a fixed sequence of operators : Multiplication (*), division (/), Add (+) And subtraction (-).)

    Usually , Positive integer n The factorial of is all less than or equal to n The product of positive integers of . for example ,factorial(10) = 10 * 9 * 8 * 7 * 6 * 5 * 4 * 3 * 2 * 1. contrary , We designed a stupid ...

  3. atitit. programing language Programming language Of Instrumentality and Material quality Duality and Language independence The essence

    atitit. programing language Programming language Of Instrumentality and Material quality Duality and Language independence The essence #--- Linguistic The duality of tools and materials Some people say that language is a tool , Some people say that language is a material .. In fact, language belongs to two properties at the same time . ...

  4. Transactional communication 、 Isolation and MVCC

    One . Transactional communication 1.1 What is the communication of affairs Transaction propagation is generally used when transactions are nested , For example, in business A It calls another method that uses transactions , Then these two transactions are committed as independent transactions , Or is it that the inner transaction is merged into the outer transaction ...

  5. ECMAScript1.1 js Writing position | Declare variables | Basic data type | Data type conversion | The operator | Implicit conversion of boolean type

    js Writing position Because I'm writing css The double quotation marks used in style , So we're writing js Single quotation marks are recommended when coding (‘’)! Inline <input type="button" value=" spot ...

  6. C++ Array operator overload 、 Function object analysis 、 Assignment operator

    string Type to access a single character #include <iostream> #include <string> #include <sstream> using name ...

  7. javascript Type system —— Boolean Boolean type

    × Catalog [1] Definition [2] Application scenarios [3] Turn to Boolean [4] Example method In front of the word Boolean value Boolean Types can be three wrapper objects Number.String and Boolean The simplest of these .Number and Stri ...

  8. Javascript Advanced application of Boolean operator in

    Object detection statements :var W3CDOM = document.getElementsByTagName && document.createElement To execute the operator && ...

  9. front end javascript data type Boolean type

    python It's capital True javascript It's lowercase true false It's also Boolean types contain only true and false , And Python The difference is that its initial is lowercase . ==       The comparison values are equal !=       It's not equal to ...

Random recommendation

  1. struts2 Learning record filter internationalization

    struts2 Contact is not a day or two , But it hasn't been used for any projects , But the teacher has always said that it has great learning value , So I'd better record what I have learned , There's no regularity in what's recorded , Just keep a backup for yourself , struts2 The most important thing is ...

  2. phpcms: 3、 ... and 、 The head contains

    1‘ title :{if isset($SEO['title']) && !empty($SEO['title'])}{$SEO['title']}{/if}{$SEO['site_title ...

  3. unix &amp;amp; linux oralce user Memory usage analysis

    Linux*********************************************************************************************** ...

  4. Alibaba cloud server deployment php Of laravel project , Buy... In Alibaba cloud ECS build Linux+Nginx+Mysql+PHP Environmental

    Buy... In Alibaba cloud ECS Choose the image system you are used to , I usually use Linux Ubuntu, therefore , The following configurations are all in Ubuntu 14.04 Stable support version of the environment to build Linux+Nginx+Mysql+PHP Environmental Science ...

  5. HDU Be the Winner [Anti-SG]

    Portal n Pile up , Take at least one at a time , The rest can be divided into two piles . The last one to win loses Watch and see Nim The game is the same ... bare Anti-SG ah #include <iostream> #include <c ...

  6. [BZOJ 4417][Shoi2013] Super vault

    4417: [Shoi2013] Super vault Time Limit: 10 Sec  Memory Limit: 256 MBSubmit: 379  Solved: 230[Submit][Status ...

  7. Java Study again

    Preface : In the past two weeks, I have been in Tencent class - Soft media -JAVA After the course of Huangpu class , I find that I'm really a rookie ,Java There's a lot more basic knowledge and knowledge needed for daily development . In this , I'm going to start over with this course Java, Become a qualified Jav ...

  8. axios Click and reuse CancelToken Prevent requests from being sent multiple times

    import axios from 'axios'; axios.defaults.timeout = 5000; axios.defaults.baseURL =''; let pending = ...

  9. Game Engine Architecture 1

    [Game Engine Architecture 1] 1.This book is really just the beginning of a fascinating and potential ...

  10. go compile go-gtk, appear invalid flag in pkg-config --libs: -Wl,-luuid Tips

    go compile go-gtk     Use go compile go-gtk, There are errors when compiling directly :   pkg-config --cflags -- gdk-2.0 gthread-2.0   pkg-config --l ...