JavaScript is a scripting language. The browser executes the script code on a line-by-row basis when reading the code. For traditional programming, all code is compiled before execution .
JavaScript variables
Like algebra, JavaScript variables can be used to hold values (such as x=2) and expressions (such as z=x+y).
- Variables must start with a letter
- Variables can also start with the $ and _ symbols (although we do not recommend this)
- Variable names are case sensitive (Y and y are different variables)
- Function names are also sensitive to case sensitivity!
Do not use quotation marks when the value you assign to a variable is numeric. If you enclose a value in quotation marks, the value is treated as text.
Creating a variable in JavaScript is often referred to as a "declaration" variable.
We use the VAR keyword to declare the variable
Declarations can also span multiple lines:
var name= "Gates", age=56,job= "CEO";
Variables that are not valued are often declared. A variable that is not declared with a value, whose value is actually undefined
If you re-declare a JavaScript variable, the value of the variable is not lost:
After the following two statements are executed, the value of the variable carname remains "Volvo":
var carname= "Volvo"; var carname;
JavaScript has a dynamic type
JavaScript has a dynamic type. This means that the same variables can be used for different types:
Instance
var x //x is Undefinedvar x = 6; //X is the number var x = "Bill"; //X is a string
Avascript Object
Objects are separated by curly braces. Inside the parentheses, the properties of the object are defined in the form of name and value pairs (name:value). Attributes are separated by commas:
Declaring variable types
When you declare a new variable, you can use the keyword "new" to declare its type:
var carname=new string;var x= new Number;var y= new Boolean;var cars= new Array;var person= new Object;
JavaScript variables are objects. When you declare a variable, a new object is created.
All things in JavaScript are objects: strings, numbers, arrays, dates, and so on.
In JavaScript, objects are data that has properties and methods
JavaScript is case sensitive. The keyword function must be lowercase and must be called with the same casing as the function name
function with return value
Sometimes, we want the function to return the value to the place where it was called.
This can be achieved by using the return statement.
When you use the return statement, the function stops execution and returns the specified value.
Grammar
function myFunction () {var x=5; return x;
}
The above function returns the value 5.
Note: The entire JavaScript does not stop executing, just the function. JavaScript will continue to execute code from where the function is called.
If you assign a value to a variable that has not been declared, the variable is automatically declared as a global variable. "---with a question (previously declared in any place is a variable is not assigned, then if it is any other place assigned, it is a global variable???) )
In addition to the commonly used calculation symbols (+,-,*,/,%) and logical symbols (|,&), there is also a number of = = =, which means that in addition to equal values and types are also equal (??? Value is equal, type may be object type? )
JavaScript Note (i)