search
HomeWeb Front-endJS Tutorialjavascript operators you must learn every day_javascript skills

Hello readers, I have already roughly understood the role of Javascript and some basic function declarations and variable declarations. Today we will continue to explain the previous content. Let’s take a look at the logic of javscript (forward sequence, branch , loop) and some simple operators

Let’s talk about some simple operation operators

  • + Plus sign: 1. Used to calculate the sum of two numbers, 2. Used to splice two strings
  • - Minus sign: 1. Used to calculate the difference between two numbers, 2. Used in front of a number to identify a negative number
  • * Multiplication sign: used to calculate the product of two numbers
  • / Division sign: used to calculate the quotient obtained after dividing the dividend by the divisor
  • % Remainder: Used to calculate the remainder after dividing the dividend by the divisor (the calculation here is an integer division, and the remainder after integer division will be obtained)
  • = Assignment: used to assign a value (can be an object, function, number, string, Boolean) to a variable

Here, we can clearly see that the operators display the results of the operations. I don’t need to go into details about addition, subtraction, multiplication and division. I believe everyone’s calculation skills should be better than mine, because I only graduated from middle school. That's it. What I want to talk about a little more is the remainder operation. In the above example, 5% 2 takes the remainder and gets 1. It is calculated like this, 5÷ 2 = 2... 1. You should have seen this in the second grade of elementary school. Calculate, dividend ÷ divisor = quotient...remainder, this remainder is the result of the remainder operation, and the equal symbol mentioned yesterday, which is the var temp = value used for assignment; we use the var keyword to To declare a variable, use = to assign a value to you. The type of the value can be an object, a function, a number, a string, or a Boolean. As I have told you before, what a function is is a function body declared with function. That is a function. , Needless to say numbers, strings are just a string of strings enclosed in quotation marks, and Boolean values ​​are a type with only two values, true and false, and there is no third one.

Let’s take a look at what the various values ​​look like

//这里我们给了一个空对象(null)
  var temp_1 = null;
  //这里我们给一个函数
  var temp_2 = function(){
   console.log("Write Something");
  };
  //这里我们给了一个字符串
  var temp_3 = "My name is MrDream";
  //这里我们给了一个boolean值
  var temp_4 = true;

These basic operations should be clear to everyone. I hope that readers will not be anxious when they see these basic things. We are still in the introductory introduction stage, so everyone must understand these basic things. In the article, I will talk about more things. Otherwise, if the foundation is not laid well, later, when I talk about something that you think is awesome, it will be meaningless if you can only copy the code and use it, and you cannot write it independently. Something you want.

Let’s further understand what the operator looks like after a small upgrade? (Note: At present, I only talk about some basic operators, and some special operators. I will explain them in some applications later, and then the understanding will be deeper)

  • += Addition: First add the two operands, and then assign the added value to the first operand
  • -= Subtraction: First subtract the two operands, and then assign the added value to the first operand
  • *= Multiplication and so on: first multiply the two operands, and then assign the added value to the first operand
  • /= Division, etc.: First divide the two operands, and then assign the added value to the first operand
  • %= Remainder: First perform the remainder operation on the two operands, and then assign the added value to the first operand

Here are some simple comparison operators

  • == Equal: Determine whether the objects on both sides of the operator are equal
  • === Absolute equality: Determine whether the objects on both sides of the operator are absolutely equal
  • !== Absolutely not equal: Determine whether the objects on both sides of the operator are absolutely unequal
  • != Not equal: Determine whether the objects on both sides of the operator are not equal
  • || Or (or): First determine whether the objects on the left and right sides of the operator are "non-empty objects or non-undefined objects". If both are, return the value on the right. If If there is a value that is not, return the value that is not that value
  • && And (and): First determine whether the objects on the left and right sides of the operator are "non-empty objects or non-undefined objects". If they are neither, return the value on the right. If there is a value If yes, return the value that is yes. If both are yes, return the one on the left.
  • ! Negation (not): After converting a value into a Boolean value, then negate it

(Note: The or and negation operators mentioned here are explained using everyone’s common understanding of logic. In fact, the internal operations involve the results of binary OR and NOT operations. We We’ll talk more about binary below) Let’s look at some examples

The following is a little bit about the operations of OR and NOT, which is a little more difficult to understand

Looking at the picture, at A, because there is no object defined on the left side of the operator, the value on the right is returned; at B, because the left side is an empty object, the value on the right is returned; at C, because there is a real value number 123 on the left , so 123 is returned; because the left side of D is the real value number -1, the value on the left is returned. One additional note: The number 0 is also a special value. If the left side is 0, then the value on the right will be returned.

To summarize the function of the OR operator: it is used to check whether the left and right sides of the operator are undefined values, null values, 0, false. If the left side is these values, the value on the right is returned. If the left side is not of these types value, return the value on the left.

Next and operation

Still talking from the picture, at A: the left and right are undefined objects and empty objects respectively, and the value on the left is returned; at B, the left is an empty object, so the left is returned; at C: the right is an undefined object, so the value on the right is returned ; D: Same as C; E: Both are non-empty objects, and the Boolean value on the left is true, so the right is returned; F: The same as E; G: Because the left is 0, it is the same as an undefined object , the empty object is the same level as false, so the left value is returned.

The last one is a non-operation

Continue to look at the picture and talk, at A: the operation is a value such as 0, false, null, undefined, etc., and when returned, the true value of the Boolean value is obtained; at B: the operation is to invert the real value, and the The main is the boolean value false. We can conclude that negation is a Boolean value, negation of an unreal value is correct, and negation of an actual value is an error.

Okay, that’s all for today. To summarize, today, I actually just talked about some very basic operators, but there are a lot of operators, so I just wrote this right to finish the expression. , and there are some special operators, which we will talk about later. As long as you make a little progress every day, it is not a dream to become a great master.

Statement
The content of this article is voluntarily contributed by netizens, and the copyright belongs to the original author. This site does not assume corresponding legal responsibility. If you find any content suspected of plagiarism or infringement, please contact admin@php.cn
Behind the Scenes: What Language Powers JavaScript?Behind the Scenes: What Language Powers JavaScript?Apr 28, 2025 am 12:01 AM

JavaScript runs in browsers and Node.js environments and relies on the JavaScript engine to parse and execute code. 1) Generate abstract syntax tree (AST) in the parsing stage; 2) convert AST into bytecode or machine code in the compilation stage; 3) execute the compiled code in the execution stage.

The Future of Python and JavaScript: Trends and PredictionsThe Future of Python and JavaScript: Trends and PredictionsApr 27, 2025 am 12:21 AM

The future trends of Python and JavaScript include: 1. Python will consolidate its position in the fields of scientific computing and AI, 2. JavaScript will promote the development of web technology, 3. Cross-platform development will become a hot topic, and 4. Performance optimization will be the focus. Both will continue to expand application scenarios in their respective fields and make more breakthroughs in performance.

Python vs. JavaScript: Development Environments and ToolsPython vs. JavaScript: Development Environments and ToolsApr 26, 2025 am 12:09 AM

Both Python and JavaScript's choices in development environments are important. 1) Python's development environment includes PyCharm, JupyterNotebook and Anaconda, which are suitable for data science and rapid prototyping. 2) The development environment of JavaScript includes Node.js, VSCode and Webpack, which are suitable for front-end and back-end development. Choosing the right tools according to project needs can improve development efficiency and project success rate.

Is JavaScript Written in C? Examining the EvidenceIs JavaScript Written in C? Examining the EvidenceApr 25, 2025 am 12:15 AM

Yes, the engine core of JavaScript is written in C. 1) The C language provides efficient performance and underlying control, which is suitable for the development of JavaScript engine. 2) Taking the V8 engine as an example, its core is written in C, combining the efficiency and object-oriented characteristics of C. 3) The working principle of the JavaScript engine includes parsing, compiling and execution, and the C language plays a key role in these processes.

JavaScript's Role: Making the Web Interactive and DynamicJavaScript's Role: Making the Web Interactive and DynamicApr 24, 2025 am 12:12 AM

JavaScript is at the heart of modern websites because it enhances the interactivity and dynamicity of web pages. 1) It allows to change content without refreshing the page, 2) manipulate web pages through DOMAPI, 3) support complex interactive effects such as animation and drag-and-drop, 4) optimize performance and best practices to improve user experience.

C   and JavaScript: The Connection ExplainedC and JavaScript: The Connection ExplainedApr 23, 2025 am 12:07 AM

C and JavaScript achieve interoperability through WebAssembly. 1) C code is compiled into WebAssembly module and introduced into JavaScript environment to enhance computing power. 2) In game development, C handles physics engines and graphics rendering, and JavaScript is responsible for game logic and user interface.

From Websites to Apps: The Diverse Applications of JavaScriptFrom Websites to Apps: The Diverse Applications of JavaScriptApr 22, 2025 am 12:02 AM

JavaScript is widely used in websites, mobile applications, desktop applications and server-side programming. 1) In website development, JavaScript operates DOM together with HTML and CSS to achieve dynamic effects and supports frameworks such as jQuery and React. 2) Through ReactNative and Ionic, JavaScript is used to develop cross-platform mobile applications. 3) The Electron framework enables JavaScript to build desktop applications. 4) Node.js allows JavaScript to run on the server side and supports high concurrent requests.

Python vs. JavaScript: Use Cases and Applications ComparedPython vs. JavaScript: Use Cases and Applications ComparedApr 21, 2025 am 12:01 AM

Python is more suitable for data science and automation, while JavaScript is more suitable for front-end and full-stack development. 1. Python performs well in data science and machine learning, using libraries such as NumPy and Pandas for data processing and modeling. 2. Python is concise and efficient in automation and scripting. 3. JavaScript is indispensable in front-end development and is used to build dynamic web pages and single-page applications. 4. JavaScript plays a role in back-end development through Node.js and supports full-stack development.

See all articles

Hot AI Tools

Undresser.AI Undress

Undresser.AI Undress

AI-powered app for creating realistic nude photos

AI Clothes Remover

AI Clothes Remover

Online AI tool for removing clothes from photos.

Undress AI Tool

Undress AI Tool

Undress images for free

Clothoff.io

Clothoff.io

AI clothes remover

Video Face Swap

Video Face Swap

Swap faces in any video effortlessly with our completely free AI face swap tool!

Hot Tools

WebStorm Mac version

WebStorm Mac version

Useful JavaScript development tools

DVWA

DVWA

Damn Vulnerable Web App (DVWA) is a PHP/MySQL web application that is very vulnerable. Its main goals are to be an aid for security professionals to test their skills and tools in a legal environment, to help web developers better understand the process of securing web applications, and to help teachers/students teach/learn in a classroom environment Web application security. The goal of DVWA is to practice some of the most common web vulnerabilities through a simple and straightforward interface, with varying degrees of difficulty. Please note that this software

ZendStudio 13.5.1 Mac

ZendStudio 13.5.1 Mac

Powerful PHP integrated development environment

Atom editor mac version download

Atom editor mac version download

The most popular open source editor

Dreamweaver CS6

Dreamweaver CS6

Visual web development tools