Network Security Internet Technology Development Database Servers Mobile Phone Android Software Apple Software Computer Software News IT Information

In addition to Weibo, there is also WeChat

Please pay attention

WeChat public account

Shulou

What is the basic knowledge of Javascript

2025-02-25 Update From: SLTechnology News&Howtos shulou NAV: SLTechnology News&Howtos > Development >

Share

Shulou(Shulou.com)06/03 Report--

Editor to share with you what the basic knowledge of Javascript, I believe that most people do not know much about it, so share this article for your reference, I hope you can learn a lot after reading this article, let's go to understand it!

Variable

Basic grammar

Var age=10;// declares a variable named age and assigns a value to it, called the initialization of the variable

Var is a JS keyword used to declare variables. We can also update variables according to the ideas of other programming languages, and we can declare multiple variables at the same time, using only one var to separate multiple variable names with English commas.

Naming convention

Consists of letters (A-Za-z), numbers (0-9), underscores (_), and dollar signs ($), such as: usrAge, num01, _ name

Strictly case-sensitive. Var app; and var App; are two variables

Cannot start with a number and must be a word with no spaces in the middle. 18age is wrong.

Cannot be keywords, reserved words. For example: var, for, while

The variable name must be meaningful.

Follow the hump naming method. The first letter is lowercase, and the first letter of the following word needs to be capitalized. MyFirstName

Data type

Introduction to data types

JS is a weakly typed or dynamic language, which means that there is no need to declare the value of a variable in advance, and the type is automatically determined while the program is running. The data type of a variable is determined by the JS engine based on the data type of the variable value to the right of the equal sign, meaning that the same variable can be used as a different type.

Var age= 10; / / this is a numeric var age= "10" / / this is a string

JS data types are divided into simple data types and complex data types.

Number String Boolean Undefined Null (simple data types are also known as basic data types)

Object Array Date function (complex data types are also known as reference data types)

But in the new syntax of ES6 and H5, the Symbol simple data type has been added (I'll talk about it later).

Number

The common ones are binary, octal, decimal and hexadecimal, adding 0 before octal and 0x before hexadecimal in JS

/ / 1. The octal number sequence range: 0~7var num1 = 07; / / corresponding to decimal 7var num2 = 019; / / corresponding to decimal 19var num3 = 08; / / corresponding to decimal 19var num3 = 2. Hexadecimal digit sequence range: 09and A~Fvar num = 0xA

Maximum value: Number.MAX_VALUE, this value is: 1.7976931348623157e+308

Minimum value: Number.MIN_VALUE, this value is: 5e-32

Alert (Number.MAX_VALUE); / / 1.7976931348623157e+308alert (Number.MIN_VALUE); / / 5e-32

Three special values

Infinity, which stands for infinity, is greater than any numerical value

-Infinity, which stands for infinitesimal, less than any number

NaN, Not a number, represents a non-numeric value

IsNaN () determines whether a variable is a non-numeric type

Var usrAge = 21console.log isOk = isNaN (userAge); console.log (isNum); / / false, 21 is not a non-numeric var usrName = "andy"; console.log (isNaN (userName)); / / true, "andy" is a non-numeric

String

Using single quotation marks, you can also nest string quotation marks. You can use single quotation marks to nest double quotes or double quotes to nest single quotation marks, but you cannot mix single and double quotation marks. The escape characters are as follows.

Get string length length

String concatenation string + any type = the new string after concatenation, if two numeric values are added, the result is a numeric value.

Boolean

True and false, when the Boolean value is added to the numeric type, the value of true is 1 and the value of false is 0.

Undefined

The use of a variable that is not assigned after declaration will have a default value of undefined

If you use an undeclared variable, an error will be reported.

Var variable;console.log (variable); / / undefinedconsole.log ('Hello' + variable); / / Hello undefinedconsole.log (11 + variable); / / NaNconsole.log (true + variable); / / NaN

Null

Var vari = null;console.log ('Hello' + vari); / / Hello nullconsole.log (11 + vari); / / 11console.log (true + vari); / / 1

Data type conversion

The data obtained by using form and prompt is string type by default, so you can't add directly, but need to convert the data type of the variable. In popular terms, it is to convert a variable of one data type into another.

Convert to string type

Convert to numeric type

Convert to Boolean type

Values that represent null or negative are converted to false, such as'', 0, NaN, null, undefined

The rest of the values are converted to true

Console.log (Boolean (')); / / falseconsole.log (Boolean (0)); / / falseconsole.log (Boolean (NaN)); / / falseconsole.log (Boolean (null)); / / falseconsole.log (Boolean (undefined)); / / falseconsole.log (Boolean ('rookie')); / / trueconsole.log (Boolean (12)); / / true extension point

Interpretive language and compiled language.

The computer must compile the program language (using a translator) into a machine language before it can execute the program.

There are two ways for translators to translate into machine languages, one is compilation and the other is interpretation. The difference lies in the different time points of translation.

The compiler compiles before the code is executed to generate intermediate code files.

The interpreter interprets in time at run time and executes immediately

Identifiers mean that developers get names for variables, parameters, and functions. Identifiers cannot be keywords or reserved words

Keywords refer to words already used by JS itself, which can no longer be used as variable names and method names

Including: break, case, catch, continue, default, delete, do, else, finally, for, function, if, in, instanceof, new, return, switch, this, throw, try, typeof, var, void, while, with

Reserved words are reserved keywords that may become keywords in the future.

Including: boolean, byte, char, class, const, debugger, double, enum, export, extends, fimal, float, goto, implements, import, int, interface, long, mative, package, private, protected, public, short, static, super, synchronized, throws, transient, volatile, etc.

These are all the contents of the article "what are the basics of Javascript". Thank you for reading! I believe we all have a certain understanding, hope to share the content to help you, if you want to learn more knowledge, welcome to follow the industry information channel!

Welcome to subscribe "Shulou Technology Information " to get latest news, interesting things and hot topics in the IT industry, and controls the hottest and latest Internet news, technology news and IT industry trends.

Views: 0

*The comments in the above article only represent the author's personal views and do not represent the views and positions of this website. If you have more insights, please feel free to contribute and share.

Share To

Development

Wechat

© 2024 shulou.com SLNews company. All rights reserved.

12
Report