- html>
- <html>
- <head>
- <meta charset="utf-8">
- <title>title>
- head>
- <body>
- <p>Undefined 与 Null 的区别p>
- <p id = "g">p>
- <script>
- document.getElementById("g").innerHTML =
- typeof undefined + "
" + - typeof null + "
" + - (null == undefined) + "
" + - (null == undefined);
- script>
- body>
- html>
Undefined 与 Null 的区别
Undefined 与 null 的值相等,但类型不相等
- html>
- <html>
- <head>
- <meta charset="utf-8">
- <title>title>
- head>
- <body>
- <p>原始数据p>
- <p id = '原始数据'>p>
- <script>
- document.getElementById("原始数据").innerHTML =
- typeof "html" + "
" + - typeof 9.9 + "
" + - typeof false + "
" + - typeof true + "
" + - typeof HTML;
- script>
- body>
- html>
原始数据
原始数据值是一种没有额外属性和方法的单一简单数据值。
typeof 运算符可返回以下原始类型之一:
string
number
Boolean
undefined
- html>
- <html>
- <head>
- <meta charset="utf-8">
- <title>title>
- head>
- <body>
- <p>复杂数据p>
- <p id = "复杂数据">p>
- <script>
- document.getElementById("复杂数据").innerHTML =
- typeof{html:"盗墓笔记",age:8.17}+"
" + - typeof[9,3,6,1] + "
" + - typeof null + "
" + - typeof function myFunc(){};
- script>
- body>
- html>
复杂数据
typeof 运算符可返回以下两种类型之一:
function
object
typeof 运算符把对象、数组或 null 返回 object。
typeof 运算符不会把函数返回 object。
typeof 运算符把数组返回为 "object",因为在 JavaScript 中数组即对象
- html>
- <html>
- <head>
- <meta charset="utf-8">
- <title>title>
- head>
- <body>
- <p>JavaScript 函数p>
- <p id = '函数'>p>
- <script>
- function myFunction(h1,h2){
- return h1 * h2;
- }
- document.getElementById("函数").innerHTML = myFunction(9,10);
- script>
- body>
- html>
JavaScript 函数是被设计为执行特定任务的代码块。
JavaScript 函数会在某代码调用它时被执行
JavaScript 函数语法
JavaScript 函数通过 function 关键词进行定义,其后是函数名和括号 ()。
函数名可包含字母、数字、下划线和美元符号(规则与变量名相同)。
圆括号可包括由逗号分隔的参数
函数参数(Function parameters)是在函数定义中所列的名称。
函数参数(Function arguments)是当调用函数时由函数接收的真实的值。
在函数中,参数是局部变量。
在其他编程语言中,函数近似程序(Procedure)或子程序(Subroutine)