Home >Web Front-end >JS Tutorial >Introduction to the basics of javascript Suitable for novices to learn_Basic knowledge
1. A brief introduction to JavaScript
Ø Most of the JavaScript mentioned on the Internet or in books refers to client-side JavaScript.
Ø JavaScript is a lightweight, interpreted, object-oriented programming language.
Ø JavaScript features
1) Control the appearance and content of the document
2) Control the browser
3) Interaction with HTML forms
4) Interaction with users
5) Use Cookie reads and writes user status
6) Others
2. Lexical structure
2.1. Character set
JavaScript programs are written using the Unicode character set.
2.2. Case Sensitive
JavaScript is a case-sensitive language.
2.3. Comments
//: //Any text on the following line is commented
/**/: in /**/Any text between is commented
2.4. Direct quantity
Direct quantity: data value that appears directly in the program
12 //Number 1.2 //Number "hello world" //String 'Hi' //String true //Boolean value false //Boolean value/JavaScript /gi //Regular expression null //Empty object { x:1, y:2 } //Object initializer [1,2,3,4,5] //Array initializer 2.5. Identifier
identification Fu is actually a name. In JAVASCRIPT, identifiers are used to name variables, functions, or labels used for certain loops in
JAVASCRIPT code.
Identifier naming rules, the first character must be a letter, underscore or dollar character, followed by letters, numbers, underscore or dollar character. Numbers are not allowed as the first character so that JAVASCRIPT can easily distinguish identifiers from numbers.
2.6. Reserved words
break
do
if
switch
typeof
case
else
in
this
var
catch
false
instanceof
throw
void
continue
finally
new
true
while
default
for
null
try
with
delete
function
return
3. Data types and values
3.1. Numbers
In JavaScript, numbers are not divided into integer types and floating point Type type, all numbers are composed of
floating point type. JavaScript uses the 64-bit floating point format defined by the IEEE754 standard to represent numbers. It can represent a maximum value of ±1.7976931348623157 x 10308 and a minimum value of ±5 x 10 -324
3.2. String
In JavaScript, string It is a sequence
consisting of Unicode characters, numbers, punctuation marks, etc., and you can use ' or " to represent a string.
3.3. Boolean
In JavaScript, the only Boolean types are true and false Two values.
3.4. Function
In JavaScript, a function is regarded as a data type. For example: var square = function(x) { return x*x; } 3.5. Object
3.6. . Array
3.7. null
The keyword null of JAVASCRIPT is a special value, which means "no value". Null is often regarded as a special value of the object type, which means the value of "no object". Null is a unique value that is different from all other values. If the value of a variable is null, then you know that its value is not a valid object, array, number, string, or Boolean value. . undefined
Undefined will be generated in the following situations:
Ø An undeclared variable is used
Ø A variable that has been declared but has not been assigned a value is used
Ø An object is used Property that does not exist