• js第一课总结


      一。  当引用了一个src=“demo.js”后,scrpit中间不能有js类的任何方法,都不会被执行。

    <!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>
    <meta http-equiv="Content-Type" content="text/html; charset=gb2312" />
    <title>使用JavaScript</title>

    </head>
    <body>

     

    <script type="text/javascript" src="demo.js"> alert("i am fine");//这个方法始终不会被执行,因为引用了外部的js

    </script>
    hello world

    </body>
    </html>

    <script></script>尽量放在head

    =============================================

    二。如果用户浏览器仅用了javasript,执行下面这段语句则会直接输出 open javascprit  ,如果没有禁用则不会输出该语句

    <noscript>

    open javascript
    </noscript>

    var box ;

    alert(box);//执行会报undefined

    alert(typeof box);//用于检测显示他的类型

    三。js中共有七中数据类型

               =====  =================================

    1.undefined  没有初始化的变量就是undefined的 比如var box;

    (box是Undefined类型,打印出来的值是undefined的 alert(typeof box)),类型返回的字符串是undefined的

    2. null var box = null    box是Null类型,值为null,类型返回是object

    备注:空的对象,表示这个对象查滚见了,里面没东西

    空对象,表示没有创建,就是一个null

    3.boolean   var box = true。 box是Boolean类型,值为true,类型返回的字符串是boolean

    4.number var box=100  box是Number类型,值为100 ,返回类型为number

    5.string var box=‘黎’ box是String类型,值为黎,类型返回的字符串是string

    6.object  var box={}; 或者var box=new Object();      box是Object 类型,值为[object Object] 类型返回的字符串为object

    7.function 

    function box(){}

    alert(typeof box);

    box是Function函数,值为function box(){}  类型返回为function

    拓展:var box = null

    表示你还没有创建对象,但是吸纳申明了对象引用而必须初始化的结果,

    你还没来得及创建对象,先声明一个对象的变量放在那边,默认初始化为nul

    var box ={}//是用于申明一个对象,或者  使用var box =new Object();用于申明一个对象

    if(box != null){

      alert(“对象已经被创建”)}

    if条件为真,会弹出这个alert

    var box ='' //创建一个字符串变量,一开始不知道使用什么字符串,所以先给他一个初始化

    var box = 0 // 数值初始化,一般用0

    var box =false  //布尔值初始化,一般一开始用false或者true

    alert(undefined ==null)//,他们都是空的,结果为true

    alert(undefined ===null)//,//数据类型也必须相等才为真,所以这句话为false 也可以使用typeof来判断类型

    alert(typeof undefined==typeof null) //结果为false

  • 相关阅读:
    10-22 训练 T2 plate
    C语言I博客作业03
    c语言I博客作业02
    数学的数字
    javascript 递归
    WEB 动画的一些实现方式
    javascript 中Object一些高效的操作方法
    javascript 中Array一些高效的操作方法
    mac os 的一些命令
    javascript 继承
  • 原文地址:https://www.cnblogs.com/xiaohouzai/p/7923346.html
Copyright © 2020-2023  润新知