Home > Article > Web Front-end > JavaScript basic syntax learning tutorial_javascript skills
Basic concepts of Javascript
i. Javascript language is a scripting language widely used in web pages.
ii. Characteristics of Javascript language:
1. Developed by Netscape, it is a scripting language that is object- and event-driven and has certain security.
2. Features:
a) Javascript is a scripting language and an interpreted language;
b) Javascript is run by the javascript interpreter in the browser and has nothing to do with the operating environment;
c) In JavaScript, less strict data types are used. The advantage of this is that it is more convenient when defining or using data, but it also brings about the problem of confusion;
d) Javascript is an object-based language, so you can create objects yourself and use the properties and methods in the objects you create to create many functions;
e) The main function of Javascript is to animate the web page, and there is also a certain amount of interaction;
f) Javascript is secure and does not allow users to access the local hard disk or modify or delete documents on the network. This can effectively prevent data loss and malicious modification.
g) Example: HTML file built-in script
<script language="javascript"> Document.write("<font color=blue>Hello,JavaScript!</font>"); </script> HTML文件外接脚本 <script src="1.js"> </script> //1.js Document.write("<font color=blue>JavaScript,Hello!</font>");
JavaScript statement
Commands issued by JavaScript statements to the browser. The purpose of a statement is to tell the browser what to do.
Semicolon ;
Semicolons are used to separate JavaScript statements.
Usually we add a semicolon at the end of each executable statement.
Another use of semicolons is to write multiple statements on one line.
Tip: You may also see cases without semicolons.
In JavaScript, terminating a statement with a semicolon is optional.
JavaScript code
JavaScript code (or just JavaScript) is a sequence of JavaScript statements.
The browser will execute each statement in the order it is written.
JavaScript code block
JavaScript statements are grouped into blocks of code.
block starts with a left curly brace and ends with a right curly brace.
block is to cause a sequence of statements to be executed together.
JavaScript functions are a classic example of combining statements in blocks.
The following example will run a function that operates on two HTML elements:
JavaScript is case sensitive
JavaScript is case-sensitive.
When writing JavaScript statements, please pay attention to whether the case switch key is turned off.
The functions getElementById and getElementbyID are different.
Similarly, the variables myVariable and MyVariable are also different.
JavaScript Comments
JavaScript will not execute comments.
We can add comments to explain JavaScript or improve the readability of the code.
Single-line comments start with //.
JavaScript multi-line comments
Multi-line comments start with /* and end with */.
JavaScript Variables
Like algebra, JavaScript variables can be used to store values (such as x=2) and expressions (such as z=x y).
Variables can have short names (like x and y) or more descriptive names (like age, sum, totalvolume).
•Variables must start with a letter
•Variables can also start with $ and _ symbols (although we don’t recommend this)
•Variable names are case sensitive (y and Y are different variables)
Tip: JavaScript statements and JavaScript variables are case-sensitive.
JavaScript data types
JavaScript variables can also hold other data types, such as text values (name="Bill Gates").
In JavaScript, a text like "Bill Gates" is called a string.
JavaScript variables come in many types, but for now, we’ll just focus on numbers and strings.
When you assign a text value to a variable, you should surround the value with double or single quotes.
Don’t use quotes when the value you assign to a variable is a numeric value. If you surround a numeric value with quotes, the value is treated as text.
JavaScript Timing Events
By using JavaScript, we have the ability to execute code after a set time interval, rather than immediately after the function is called. We call them timing events.
Using timing events in JavaScript is easy, two key methods are:
setTimeout()Execute code at some time in the future
clearTimeout()Cancel setTimeout()
Through the above content, I have introduced you to the basic syntax of JavaScript, and I hope it will be helpful to you in your future work and study.