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. 关于App自动化执行链接Appium服务包名正确但是报错An unknown server-side error occurred while processing the command

    在执行链接Appium服务时连接失败可能原因: 1.报错截图: 2.先检查包名是否正确(正常情况下包名不会错误)通过命令行查看包名:aapt dump badging xxx.apk 3.检查对应包的 ...

  2. Yaml学习文档

    pdf文档地址 http://yaml.org/spec/ JS-Yaml demo地址 http://nodeca.github.io/js-yaml/

  3. anoconda 神经网络 相关操作

    1. conda 相关操作 建立新环境:conda crearte -n NewName python=版本(3.6) 激活环境:conda activate NewName 关闭环境:conda d ...

  4. HyperLedger/Fabric SDK使用Docker容器镜像快速部署上线

    HyperLedger/Fabric SDK Docker Image 该项目在github上的地址是:https://github.com/aberic/fabric-sdk-container ( ...

  5. WebShell代码分析溯源(第1题)

    <?php $POST['POST']='assert';$array[]=$POST;$array[0]['POST']($_POST['assert']);?> assert,是php ...

  6. Linux读书笔记第五章

    主要内容: 什么是系统调用 Linux上的系统调用实现原理 一个简单的系统调用的实现 1. 什么是系统调用 简单来说,系统调用就是用户程序和硬件设备之间的桥梁. 用户程序在需要的时候,通过系统调用来使 ...

  7. Mac用户抓包软件Charles 4.0 破解 以及 抓取Https链接设置

    相信大家曾经都是Window的用户,作为前端哪能没有一款抓包工具,抓包工具可以非常便捷的帮助我们分析接口返回报文数据,快速定位问题. 曾经横扫window用户的Fiddler便是我们的挚爱,然而,作为 ...

  8. jvm垃圾回收机制和常见算法

    这是朋友给的面试题里边的,具体地址已经找不到,只能对原作者说声抱歉了: 理论上来讲sun公司只定义了垃圾回收机制规则,而步局限于其实现算法,因此不同厂商生产的虚拟机采用的算法也不尽相同. GC(Gar ...

  9. ElasticSearch 2 (21) - 语言处理系列之单词识别

    ElasticSearch 2 (21) - 语言处理系列之单词识别 摘要 一个英语单词相对容易识别:因为英语单词是被空格或(某些)标点符号隔开的.但在英语中也有反例:you're 这个词是一个单词还 ...

  10. 在ubuntu下运行python脚本

    转自http://www.cnblogs.com/hester/p/5575658.html 1. 运行方式一 新建test.py文件: 1 touch test.py 然后vim test.py打开 ...