1,js有哪些数据类型,数据类型的判断函数?

String,Number,Boolean,Null,Undefined,Object

判断函数有:typeof,instanceof,constructor,prototype

接下来我们一一对这些进行举例子。

  1. var a = 'nihao';
  2. var b = 222;
  3. var c = [1,2,3];
  4. var d = new Date();
  5. var e = function(){alert('hanshu');};
  6. var f = function(){this.name = 'hanmeimei'};
  7. alert(typeof a);//string
  8. alert(typeof a == String);// false
  9. alert(typeof b);// number
  10. alert(typeof c);// object
  11. alert(typeof d);// object
  12. alert(typeof e);// function
  13. alert(typeof f);// function
  14. alert(c instanceof Array);//true
  15. alert(e instanceof Function);//true
  16. alert(c.constructor === Array);//true
  17. function A(){};
  18. function B(){};
  19. A.prototype = new B(); //A继承自B注意: constructor 在类继承时会出错
  20. var aObj = new A();
  21. alert(aObj.constructor === B);// -----------> true;
  22. alert(aObj.constructor === A);// -----------> false;
  23. //而instanceof方法不会出现该问题,对象直接继承和间接继承的都会报true:
  24. alert(aObj instanceof B); //----------------> true;
  25. alert(aObj instanceof A); //----------------> true;
  26. //解决construtor的问题通常是让对象的constructor手动指向自己:
  27. aObj.constructor = A;//将自己的类赋值给对象的constructor属性
  28. alert(aObj.constructor === B);// -----------> flase;
  29. alert(aObj.constructor === A);//true
  30. //prototype
  31. alert(Object.prototype.toString.call(a) === '[object String]');//true;
  32. alert(Object.prototype.toString.call(b) === '[object Number]');//true;
  33. alert(Object.prototype.toString.call(c) === '[object Array]');//true;
  34. alert(Object.prototype.toString.call(d) === '[object Date]');//true;
  35. alert(Object.prototype.toString.call(e) === '[object Function]');//true;
  36. alert(Object.prototype.toString.call(f) === '[object Function]');//true;

2,编写一个js函数,时时显示当前时间,格式:“年-月-日 时:分:秒”

  1. function nowtime(){
  2. var nowDate = new Date();
  3. var year = nowDate.getFullYear();
  4. var month = nowDate.getMonth() + 1;
  5. var day = nowDate.getDate();
  6. var hours = nowDate.getHours();
  7. var minutes = nowDate.getMinutes();
  8. var second = nowDate.getSeconds();
  9. return year + '-' + month + '-' + day +' '+hours+':'+minutes +':'+second;
  10. }
  11. alert(nowtime());

3,显示隐藏dom元素

使用jquery

  1. $(function(){
  2. $("#div").show();
  3. $("#div").hide();
  4. });

4,如果添加HTML元素的事件处理,几种方法

1,直接元素中添加:

  1. <a href="###" onclick="fn();" >click</a>

2,找到dom节点如:

  1. var ob = document.getElementById("div");
  2. ob.onclick = function(){};

3,使用jquery添加静态的dom节点的事件

  1. $("#div").click(function(){});
  2. //动态生成的节点的话:
  3. $("#div").on("click",function(){});
  4. $("#div").live("click",function(){});

5,如何控制alert中的换行

  1. alert('nihao\nnihao');

6,判断字符串中出现次数最多的字符,统计这个次数。

7,判断字符串是否是这样组成的,第一个必须是字母,后面可以是字母,数字,下划线,总长度为5-20

8,请编写一个javascript函数parseQueryString,他的用途是把URL参数解析为一个对象,如:

var url=“http:witmax,cn/index.php?key0=0&key1=1&key2=2”;

很多题目未完待续

js简单的面试题的更多相关文章

  1. js简单 图片版时钟,带翻转效果

    js简单 图片版时钟,带翻转效果 <!DOCTYPE html> <html> <head> <meta charset="UTF-8"& ...

  2. js简单操作Cookie

    贴一段js简单操作Cookie的代码: //获取指定名称的cookie的值 function getCookie(objName) { var arrStr = document.cookie.spl ...

  3. js简单弹出层、遮罩层

    <html> <head> <title>js简单弹出层</title> <style> /*阴影边框效果*/ .box-shadow-1 ...

  4. Tourist.js – 简单灵活的操作指南和导航插件

    Tourist.js 是一个基于 Backbone 和 jQuery 开发的轻量库,帮助你在应用程序创建简单易用的操作指南和导航功能.相比网站,它更适合用于复杂的,单页网站类型的应用程序.Touris ...

  5. js简单显示和隐藏div,触发超链接,动态更改button值,setInterval()简单使用,jquery easyui弹出框简单使用 .

    js简单显示和隐藏div .<!DOCTYPE html> .<html> .<head> .<meta charset="UTF-8"& ...

  6. Gulp.js - 简单、直观的自动化项目构建工具

    Gulp.js 是一个简单.直观的构建系统.崇尚代码优于配置,使复杂的任务更好管理.通过结合 NodeJS 的数据流的能力,你能够快速构建.通过简单的 API 接口,只需几步就能搭建起自己的自动化项目 ...

  7. Node.js简单介绍并实现一个简单的Web MVC框架

    编号:1018时间:2016年6月13日16:06:41功能:Node.js简单介绍并实现一个简单的Web MVC框架URL :https://cnodejs.org/topic/4f16442cca ...

  8. JS简单入门教程

    JS简单教程 使用方法:放到任意html页面的head标签下 Test1方法弹出当前时间对话框 Test2方法for循环输出 Test3方法for(…in…)输出数组内容 <script typ ...

  9. js简单实现链式调用

    链式调用实现原理:对象中的方法执行后返回对象自身即可以实现链式操作.说白了就是每一次调用方法返回的是同一个对象才可以链式调用. js简单实现链式调用demo Object.prototype.show ...

随机推荐

  1. 英特尔和 Valve* 将英特尔® Embree 光线追踪技术添加至全新 Steam* Audio 插件

    本文从英特尔® Embree 光线追踪技术着手,深入探讨英特尔与 Valve 合作带来的优势:一方面,开发人员使用英特尔高度优化的库创建场景,可以显著加快编译速度:另一方面,逼真的声效可以增强游戏性, ...

  2. 一、Unity Editor自定义菜单

    官方文档:https://unity3d.com/cn/learn/tutorials/topics/interface-essentials/unity-editor-extensions-menu ...

  3. 《陪孩子像搭积木一样学编程》,一起来玩Scratch(1)使用Scratch编程的基本流程

    编程是一件很有趣的事情.初次接触编程,你可能不知所措,别担心,这并不复杂.首先,为了让读者对编程有大概的了解,可以把编写Scratch程序的过程分成7个步骤(如图1.8).注意,这是理想状态.在实际的 ...

  4. 《Linux内核分析》第三周

    [李行之原创作品 转载请注明出处 <Linux内核分析>MOOC课程http://mooc.study.163.com/course/USTC-1000029000] <Linux内 ...

  5. Feature List

    我组最终决定所做的软件工程项目是Bing词典(UWP)的背单词模块,下面是初步定下的Feature List. 按用户场景变化顺序列举(假设是新用户): 1.用户可通过点击“背单词”标识或按钮进入背单 ...

  6. 组件 -- Alert

    alert的背景色: alert-primary alert-secondary alert-success . . . .alert : 警告框类 .data-dismiss = "ale ...

  7. Alpha 冲刺一

    团队成员 051601135 岳冠宇 051604103 陈思孝 031602629 刘意晗 031602248 郑智文 031602234 王淇 会议照片 项目燃尽图 项目进展 界面(简陋) 登录界 ...

  8. Ubuntu 14.04 installation & bugs on Alienware-13

    列一下Alienware 13笔记本配置: Processor: Intel Core 5th Generation i5-5200U Processor (3M Cache, up to 2.70 ...

  9. Docker(九)-Docker创建Selenium容器

    SeleniumHQ官方项目:https://github.com/seleniumHQ/docker-selenium 项目目前快速迭代中. Selenium 这里主要针对的是 Selenium G ...

  10. Codeforces Round #426 (Div. 1) B The Bakery (线段树+dp)

    B. The Bakery time limit per test 2.5 seconds memory limit per test 256 megabytes input standard inp ...