


Selected variable basics of JavaScript (super detailed learning sharing!)
This article talks about the basics of JavaScript variables. First, let’s talk about the basic concepts of variables and the data types of scalars. I hope it will be helpful to everyone, let’s work together!
Variables
##1.1 The concept of variables:
A variable refers to a named storage unit in the program. Its main function is to provide a container for storing information for data operations. A variable can be thought of as a container that holds data.1.2 Declaration and assignment of variables
In JavaScript, variables need to be declared before using them. The system keyword var is used to declare variables. When declaring a variable, you can also use the assignment number "=" to assign a value to the variable. The syntax format is as follows:
var 变量名 = 变量值Example:
var name ; //声明一个变量 var name,city,like ; //声明多个变量,多个变量之间用英文状态下的逗号分开 var name = "阿泽"; //声明一个变量并且赋值
1.3 Naming of variables Rules
- Variables cannot start with a number and can start with a letter or an underscore.
- #JavaScript variable names are case-sensitive.
- You cannot use keywords in JavaScript as variable names.
#2. Data type of variable
The key to the type of variable lies in the type of value2.1 Numeric type
Numeric type variables can be used for mathematical operations, including: integer type, floating point type and NaNvar a = 10; var y = 0.1; var x = 100;The more special one is: NaN (not a number) is not a number. When converting other data types into numeric types, the conversion cannot be performed, but the program cannot report an error. In this case, a NaN value will be returned. The following situation:
<html> <head> <meta http-equiv="Content-Type" content="text/html; charset=utf-8"> <title>php.cn</title> <script> var length = "500m"; length = length*5; document.write(length); </script> </head> <body> </body> </html>Now we want the length of something to be 5 times its original length. A string cannot be converted into a meaningful value and can only be converted into NaN
A string of numbers can be converted into a meaningful numerical value. The length can be modified to a string of pure numbers and the viewing result can be output.
2.2 Character type
<!DOCTYPE html> <html lang="en"> <head> <meta charset="UTF-8"> <meta name="viewport" content="width=device-width, initial-scale=1.0"> <meta http-equiv="X-UA-Compatible" content="ie=edge"> <title>Document</title> <script> var name = "阿泽"; var str = "我的名字是'" +name+"'" document.write(str) </script> </head> <body> </body> </html>The plus sign is the string connector. If you want to nest double quotes within double quotes, the double quotes inside must be escaped (\"). Escape characters in JS It is
backslash (\) . Commonly used escape characters for
\',
\",
\\ ,
\r,
\n, etc.
<!DOCTYPE html> <html lang="en"> <head> <meta charset="UTF-8"> <meta name="viewport" content="width=device-width, initial-scale=1.0"> <meta http-equiv="X-UA-Compatible" content="ie=edge"> <title>Document</title> <script> var name = "阿泽"; var str = "我的名字叫做\"" +name+"\"" document.write(str) </script> </head> <body> </body> </html
2.3 Boolean type
var a = true; var b = falseBoolean types are commonly used in if conditional judgment statements, for example:
<!DOCTYPE html> <html lang="en"> <head> <meta charset="UTF-8"> <meta name="viewport" content="width=device-width, initial-scale=1.0"> <meta http-equiv="X-UA-Compatible" content="ie=edge"> <title>Document</title> <script> var a = 10; var b = 110; if(x>y){ document.write(a+"比"+b+"大"); }else{ document.write(b+"比"+a+"大"); } </script> </head> <body> </body> </html>
2.4 Undefined type
undefined.
<!DOCTYPE html> <html lang="en"> <head> <meta charset="UTF-8"> <meta name="viewport" content="width=device-width, initial-scale=1.0"> <meta http-equiv="X-UA-Compatible" content="ie=edge"> <title>Document</title> <script> var x; document.write(x); </script> </head> <body> </body> </html>
2.5 Empty type
null.
<!DOCTYPE html> <html lang="en"> <head> <meta charset="UTF-8"> <meta name="viewport" content="width=device-width, initial-scale=1.0"> <meta http-equiv="X-UA-Compatible" content="ie=edge"> <title>Document</title> <script> var x = null; var a = 100; var a = null ; document.write(x); document.write(a); </script> </head> <body> </body> </html>[Recommended learning:
javascript advanced tutorial]
The above is the detailed content of Selected variable basics of JavaScript (super detailed learning sharing!). For more information, please follow other related articles on the PHP Chinese website!

JavaScript's application in the real world includes front-end and back-end development. 1) Display front-end applications by building a TODO list application, involving DOM operations and event processing. 2) Build RESTfulAPI through Node.js and Express to demonstrate back-end applications.

The main uses of JavaScript in web development include client interaction, form verification and asynchronous communication. 1) Dynamic content update and user interaction through DOM operations; 2) Client verification is carried out before the user submits data to improve the user experience; 3) Refreshless communication with the server is achieved through AJAX technology.

Understanding how JavaScript engine works internally is important to developers because it helps write more efficient code and understand performance bottlenecks and optimization strategies. 1) The engine's workflow includes three stages: parsing, compiling and execution; 2) During the execution process, the engine will perform dynamic optimization, such as inline cache and hidden classes; 3) Best practices include avoiding global variables, optimizing loops, using const and lets, and avoiding excessive use of closures.

Python is more suitable for beginners, with a smooth learning curve and concise syntax; JavaScript is suitable for front-end development, with a steep learning curve and flexible syntax. 1. Python syntax is intuitive and suitable for data science and back-end development. 2. JavaScript is flexible and widely used in front-end and server-side programming.

Python and JavaScript have their own advantages and disadvantages in terms of community, libraries and resources. 1) The Python community is friendly and suitable for beginners, but the front-end development resources are not as rich as JavaScript. 2) Python is powerful in data science and machine learning libraries, while JavaScript is better in front-end development libraries and frameworks. 3) Both have rich learning resources, but Python is suitable for starting with official documents, while JavaScript is better with MDNWebDocs. The choice should be based on project needs and personal interests.

The shift from C/C to JavaScript requires adapting to dynamic typing, garbage collection and asynchronous programming. 1) C/C is a statically typed language that requires manual memory management, while JavaScript is dynamically typed and garbage collection is automatically processed. 2) C/C needs to be compiled into machine code, while JavaScript is an interpreted language. 3) JavaScript introduces concepts such as closures, prototype chains and Promise, which enhances flexibility and asynchronous programming capabilities.

Different JavaScript engines have different effects when parsing and executing JavaScript code, because the implementation principles and optimization strategies of each engine differ. 1. Lexical analysis: convert source code into lexical unit. 2. Grammar analysis: Generate an abstract syntax tree. 3. Optimization and compilation: Generate machine code through the JIT compiler. 4. Execute: Run the machine code. V8 engine optimizes through instant compilation and hidden class, SpiderMonkey uses a type inference system, resulting in different performance performance on the same code.

JavaScript's applications in the real world include server-side programming, mobile application development and Internet of Things control: 1. Server-side programming is realized through Node.js, suitable for high concurrent request processing. 2. Mobile application development is carried out through ReactNative and supports cross-platform deployment. 3. Used for IoT device control through Johnny-Five library, suitable for hardware interaction.


Hot AI Tools

Undresser.AI Undress
AI-powered app for creating realistic nude photos

AI Clothes Remover
Online AI tool for removing clothes from photos.

Undress AI Tool
Undress images for free

Clothoff.io
AI clothes remover

AI Hentai Generator
Generate AI Hentai for free.

Hot Article

Hot Tools

Atom editor mac version download
The most popular open source editor

SublimeText3 Linux new version
SublimeText3 Linux latest version

SublimeText3 Mac version
God-level code editing software (SublimeText3)

SublimeText3 English version
Recommended: Win version, supports code prompts!

SAP NetWeaver Server Adapter for Eclipse
Integrate Eclipse with SAP NetWeaver application server.