网创优客建站品牌官网
为成都网站建设公司企业提供高品质网站建设
热线:028-86922220
成都专业网站建设公司

定制建站费用3500元

符合中小企业对网站设计、功能常规化式的企业展示型网站建设

成都品牌网站建设

品牌网站建设费用6000元

本套餐主要针对企业品牌型网站、中高端设计、前端互动体验...

成都商城网站建设

商城网站建设费用8000元

商城网站建设因基本功能的需求不同费用上面也有很大的差别...

成都微信网站建设

手机微信网站建站3000元

手机微信网站开发、微信官网、微信商城网站...

建站知识

当前位置:首页 > 建站知识

弱类型语言javascript开发中的示例分析

这篇文章主要介绍了弱类型语言javascript开发中的示例分析,具有一定借鉴价值,感兴趣的朋友可以参考下,希望大家阅读完这篇文章之后大有收获,下面让小编带着大家一起了解一下。

为蓬莱等地区用户提供了全套网页设计制作服务,及蓬莱网站建设行业解决方案。主营业务为网站建设、成都做网站、蓬莱网站设计,以传统方式定制建设网站,并提供域名空间备案等一条龙服务,秉承以专业、用心的态度为用户提供真诚的服务。我们深信只要达到每一位用户的要求,就会得到认可,从而选择与我们长期合作。这样,我们也可以走得更远!

测试1: (未声明变量自动提升为全局变量)

test1();
function test1() {
  function setName() {
    name = '张三'; // 此处没有var声明,提升至全局
  }
  setName();
  console.log(name);// '张三'
}

测试2: (函数内部局部变量的变量提升)

test2();
function test2() {
  var a = 1;
  function haha() {
    console.log(a);
    var a=1;
  }
  haha(); // undefined
}

测试3: (给window对象挂载属性,作用域提升至全局)

test3();
function test3() {
  var b=2;
  function hehe(){
    window.b = 3; // 此时的b为全局变量的b
    console.log(b); // 此时的b是函数test3()里的b为2
  }
  hehe();
}

测试4: (变量提升,局部作用域的综合)

test4();
function test4() {
  c = 5;
  function heihei() {
    var c;
    window.c = 3;
    console.log(c); // 函数heihei内的c为undefined
    console.log(window.c); // 3
  }
  heihei();
}

测试5: (数组的长度的问题)

test5();
function test5() {
  var arr = [];
  arr[0] = '1';
  arr[1] = 'b';
  arr[9] = 100;
  console.log(arr.length); // 10
}

测试6: (等与全等的问题)

test6();
function test6() {
  var a = 1;
  console.log(a++); // 1
  console.log(++a); // 3
  console.log(null == undefined); // true
  console.log(null === undefined);// false
  console.log(1 == "1"); // true
  console.log(1 === "1"); // false
  console.log(NaN === NaN) // false;
}

测试7: (类型相关)

test7();
function test7() {
  console.log(typeof 1); // number
  console.log(typeof "hello"); // string
  console.log(typeof typeof "hello"); // string
  console.log(typeof !!"hello"); // boolean
  console.log(typeof /[0-9]/); // object
  console.log(typeof {}); // object
  console.log(typeof null); // object
  console.log(typeof undefined); // undefined
  console.log(typeof [1, 2, 3]); // object
  console.log(toString.call([1, 2, 3])); // [object Array]
  console.log(typeof function () {}); // function
}

测试8: (parse函数相关)

test8();
function test8() {
  console.log(parseInt(3.14));// 3
  console.log(parseFloat('3.01aaa'));// 3.01
  console.log(parseInt('aa1.2'));// NaN;
  console.log(parseInt('8.00',16));// 8
  console.log(parseInt('0x8',16));// 8
  console.log(parseInt('8.00',10));// 8
  console.log(parseInt('010',8));// 10
  console.log(parseInt('1000',2));// 1000
}

测试9: (变量提升,函数提升与return后阻断执行)

test9();
function test9() {
  function bar() {
    return foo;
    foo = 10;
    function foo(){};
  }
  console.log(typeof bar()); // 'function'
}

测试10: (作用域与函数提升)

test10();
function test10() {
  var foo = 1;
  function bar() {
    foo = 10;
    console.log(typeof foo);
    return;
    function foo(){};
  }
  bar(); // number
  console.log(foo); // 1
}

测试11: (变量提升与函数提升)

test11();
function test11() {
  console.log(typeof a); // function
  var a = 3;
  function a(){};
  console.log(typeof a); // number
}

测试12: (arguments对象)

test12();
function test12() {
  function foo(a) {
    console.log(a);// 1
    arguments[0] = 2;
    console.log(a);// 2
    console.log(arguments.length);// 3
  }
  foo(1,3,4);
}

测试13: (中间函数名,直接使用会报错)

test13();
function test13() {
  var foo = function bar(name) {
    console.log("hello " + name);
  }
  foo("world");
  console.log(bar); // 此处会报错 bar is not defined
}

测试14: (在js中定时器,最后执行,涉及到的知识点是事件循环和事件队列)

test14();
function test14() {
  function foo() {
    console.log('I am foo');
  }
  console.log('正常执行');
  setTimeout((function(){
    console.log('定时器大灰狼来啦');
  }),0);
  foo();
}

感谢你能够认真阅读完这篇文章,希望小编分享的“弱类型语言javascript开发中的示例分析”这篇文章对大家有帮助,同时也希望大家多多支持创新互联,关注创新互联行业资讯频道,更多相关知识等着你来学习!


本文名称:弱类型语言javascript开发中的示例分析
转载注明:http://bjjierui.cn/article/pihioi.html

其他资讯