Home > Web Front-end > JS Tutorial > body text

Introduction to the basic usage of js variables

王林
Release: 2020-04-16 09:21:48
forward
2330 people have browsed it

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';
Copy after login

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 = &#39;abc123&#39;;
function fnAlert(){
  alert(sTr);
};
fnAlert();
</script>
Copy after login

2. JavaScript comments

<script type="text/javascript">  
// 单行注释
var iNum = 123;
/* 
  多行注释
  1、...
  2、...
*/
var sTr = &#39;abc123&#39;;
</script>
Copy after login

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!

Related labels:
source:jb51.net
Statement of this Website
The content of this article is voluntarily contributed by netizens, and the copyright belongs to the original author. This site does not assume corresponding legal responsibility. If you find any content suspected of plagiarism or infringement, please contact admin@php.cn
Popular Tutorials
More>
Latest Downloads
More>
Web Effects
Website Source Code
Website Materials
Front End Template
About us Disclaimer Sitemap
php.cn:Public welfare online PHP training,Help PHP learners grow quickly!