Js_其他数据类型
来源:互联网 发布:胡雪岩 知乎 编辑:程序博客网 时间:2024/06/05 03:27
<%@ Page Language="C#" AutoEventWireup="true" CodeFile="其他数据类型.aspx.cs" Inherits="其他数据类型" %><!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd"><html xmlns="http://www.w3.org/1999/xhtml"><head runat="server"> <title>其他数据类型</title></head><body> <form id="form1" runat="server"> <div> <script type="text/javascript"> //函数,在js中,函数充当两个角色,一是数据类型方面,一是子程序方面 //js没有使用类的概念,在此,用函数来定义用户自定义数据类型 //示例: //function TypeName([arg,...]) //用function关键字定义数据类型TypeName,其构造函数带可选参数arg //{ // this.arg = arg; //} //定义一种数据类型表示电脑,包含cpu和ram两种属性 function Computer(cpu,ram) { this.cpu = cpu; this.ram = ram; } var myComputer = new Computer("i3,350M","2G"); //创建一个电脑实例 document.write(myComputer.cpu + "是CPU的型号," + myComputer.ram + "是内存的容量<br>"); //空值:null,表示什么都没有(无内容) //不确定的类型:undefined,在应用中null和undefined实际意义是等效的 var x = 10; var y = null; var z; //注意!该变量未赋任何值 if(x == null) { document.write("x的值为空<br>"); } else { document.write("y的值为空<br>"); } if(y == z) { document.write("null和undefined是等效的"); } else { document.write("null和undefined不是等效的"); } </script> </div> </form></body></html>