In addition to Weibo, there is also WeChat
Please pay attention
WeChat public account
Shulou
2025-01-17 Update From: SLTechnology News&Howtos shulou NAV: SLTechnology News&Howtos > Development >
Share
Shulou(Shulou.com)06/01 Report--
In this article, the editor introduces "what is the core grammar of JavaScript" in detail, the content is detailed, the steps are clear, and the details are handled properly. I hope this article "what is the core grammar of JavaScript" can help you solve your doubts.
What is JavaScript?
JavaScript is an object-based and event-driven scripting language with security performance, which has been widely used in Web application development. It is often used to add a variety of dynamic functions to web pages and provide users with a more smooth and beautiful browsing effect. Usually JavaScript scripts implement their own functions by embedding them in HTML.
Characteristics of JavaScript
JavaScript composition
Daily use of JavaScript
The basic structure of JavaScript
Example:
... Can be included anywhere in the document, as long as the code is read and loaded into memory before being used
The implementation principle of JavaScript
The way JavaScript is referenced in a web page
1. Use label
two。 External JS file
3. Directly in the HTML tag
JavaScript core syntax:
① declares variables before assigning values
Var width
Width=5
Var-keyword used to declare variables
Width-variable name
② declares and assigns variables simultaneously
Var catName= Pippi
Var x, y, zonal 10
③ does not declare direct assignment [generally not used]
Width=5
Variables can be used directly without declaration, but this method is error-prone, difficult to find and debug, and is not recommended.
① undefined: example: var width
The variable width has no initial value and will be assigned the value undefined
② null: represents a null value equal to the undefined value
③ number:
Var iNum=23; / / Integer
Var iNum=23.0;? / / floating point number
④ Boolean:true and false, but JS will parse them into 1 position 0.
⑤ String: a group of text var string1= "This is a string" enclosed in quotation marks (single or double quotation marks)
The return value of typeof detection variable; the return value of typeof operator is as follows:
① undefined: the variable is declared but not assigned.
② string: a string declared in single or double quotation marks.
③ boolean:true or false.
④ number: integer or floating point number.
Objects, arrays, and null in ⑤ object:javascript.
① attribute:
String object. Length
Var str= "this is JavaScript"
Var strLength=str.length;? / / length is 18
② method:
String object. Method name ()
Split (str): if the syntax is written as width.split ("") [space between colons] then: width height hello world will be split into: width,height,hello,world If the grammar is written as width.split (") [there is no space between colons] at this point: width height hello world will be split into: wrecery iMagiRegy t, hPerry ePersonnce gPercience hPerry, hPerry ePersonlPersonlPersonlPerspectiveo, wPhonePersonlMagnedPersonlMagol d.
① creates an array:
② assigns values to array elements:
Method 1: var fruit=new Array ("apple", "orange", "peach", "banana")
Method 2:
Var fruit=new Array (4)
Fruit [0] = "apple"
Fruit [1] = "orange"
Fruit [2] = "peach"
Fruit [3] = "banana"
③ access array:
Array name [subscript]
More methods can be found in the JavaScrpt Array object reference manual:
① if conditional statement
Zero zero null, "", undefined,NaN,false- in If turns out to be false; and everything else is true!
② switch multi-branch statement
③ for, while Loop statement
④ for-in
I is the subscript of the array. In this array needs to query all array subscripts.
① break
② continue
The ① one-line comment begins with / / and ends with the end of the line:
/ / alert ("Congratulations! successful registration")
/ / A prompt for the success of a registered member pops up on the same page as above
/ / comment
If you enter and type something in a single-line comment on the page, you will get an error: Uncaught ReferenceError: XXXX is not defined
The ② multiline comment ends with a symbol indicating that the middle statement is a comment in the program
[output generally uses alert; input using prompt;, but later use of alert is not recommended, and console.Log () is generally used in real development]
① alert () [commonly used in warnings or prompts]:
Alert ("prompt message")
② prompt ()
Prompt ("prompt message", "default information for input box")
Prompt ("Please enter your favorite color", "red")
Prompt ("Please enter your favorite color", ")
① code is case sensitive
An error will be reported when lowercase is uppercase: Uncaught SyntaxError: Unexpected identifier
Names of ② variables, objects, and functions
When declaring the names of variables, objects, and functions, uppercase, number, underscore, dollar sign are fine, but they must start with letters, underscores, and dollar signs.
Otherwise, an error will be reported: Uncaught SyntaxError: Invalid or unexpected token
③ semicolon
If you don't write it, you will get an error: Uncaught SyntaxError: Invalid or unexpected token
Print the information directly and see the specific information directly on the page
[but generally use console.Log (), because using alert () is easy to forget to delete, when using alert () for pop-up, the final product launch will reduce the user experience, so using console.Log () will avoid this problem]
Meaning of function: similar to the method in Java, it is a block of code statements that accomplish a specific task; it is easier to use: do not have to define belonging to a class, but use it directly; function classification: system functions and custom functions
ParseInt ("string"): converts a string to an integer number
For example, parseInt ("86") converts the string "86" to an integer value of 86
When parseInt ("86a"), the output is still 86
The output is still 86 when parseInt ("86a21")
Output NaN when parseInt ("a86a")
ParseFloat ("string"): converts a string to a floating point number
For example, parseFloat ("34.45") converts the string "34.45" into a floating point value of 34.45
IsNaN (): used to check whether its parameter is non-numeric
IsNaN ("111") outputs false
IsNaN (true) outputs false
IsNaN ("true") outputs true
IsNaN ("aaa") outputs true
IsNaN ("111a") outputs true
Custom function
1. Define function
two。 Call function
Function calls are generally used with events of form elements, calling format
Event name =? "function name ()"?
First, call no-parameter function
Call the no-parameter function and output "Welcome to learn JavaScript" 5 times.
Example:
When you click this button, call the function study (? ) to execute the code in the function body
Second, call the function with parameters
According to the number of times you enter, "Welcome to learn JavaScript" is displayed.
Example:
When you click this button, call the function study (count) to execute the code in the function body
After reading this, the article "what is the Core Grammar of JavaScript" has been introduced. If you want to master the knowledge points of this article, you still need to practice and use it yourself to understand it. If you want to know more about related articles, 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.
Continue with the installation of the previous hadoop.First, install zookooper1. Decompress zookoope
"Every 5-10 years, there's a rare product, a really special, very unusual product that's the most un
© 2024 shulou.com SLNews company. All rights reserved.