Home > Article > Web Front-end > Introduction to the basic usage of js variables
JavaScript is a weakly typed language, and the variable type of JavaScript is determined by its value. To define a variable, you need to use the keyword 'var'
var iNum = 123; var sTr = 'asd'; //同时定义多个变量可以用","隔开,公用一个‘var'关键字 var iNum = 45,sTr='qwe',sCount='68';
Variable type
Five basic data types:
1, number numeric type
2. string string type
3. boolean Boolean type true or false
4. undefined undefined type, the variable declaration is not initialized, and its value is undefined
5. null The null type represents an empty object. If the defined variable is going to save the object in the future, the variable can be initialized to null. If the object cannot be obtained on the page, the returned value is null
A composite type :
object
javascript statements and comments
1. A javascript statement should end with ";"
<script type="text/javascript"> var iNum = 123; var sTr = 'abc123'; function fnAlert(){ alert(sTr); }; fnAlert(); </script>
2. JavaScript comments
<script type="text/javascript"> // 单行注释 var iNum = 123; /* 多行注释 1、... 2、... */ var sTr = 'abc123'; </script>
Variables, functions, properties, and function parameter naming conventions
1. Case-sensitive;
2.The first character must It is a letter, underscore (_) or dollar sign ($);
3. Other characters can be letters, underscores, dollar signs or numbers
Recommended tutorial: js tutorial
The above is the detailed content of Introduction to the basic usage of js variables. For more information, please follow other related articles on the PHP Chinese website!