js简单的面试题
1,js有哪些数据类型,数据类型的判断函数?
String,Number,Boolean,Null,Undefined,Object
判断函数有:typeof,instanceof,constructor,prototype
接下来我们一一对这些进行举例子。
- var a = 'nihao';
- var b = 222;
- var c = [1,2,3];
- var d = new Date();
- var e = function(){alert('hanshu');};
- var f = function(){this.name = 'hanmeimei'};
- alert(typeof a);//string
- alert(typeof a == String);// false
- alert(typeof b);// number
- alert(typeof c);// object
- alert(typeof d);// object
- alert(typeof e);// function
- alert(typeof f);// function
- alert(c instanceof Array);//true
- alert(e instanceof Function);//true
- alert(c.constructor === Array);//true
- function A(){};
- function B(){};
- A.prototype = new B(); //A继承自B注意: constructor 在类继承时会出错
- var aObj = new A();
- alert(aObj.constructor === B);// -----------> true;
- alert(aObj.constructor === A);// -----------> false;
- //而instanceof方法不会出现该问题,对象直接继承和间接继承的都会报true:
- alert(aObj instanceof B); //----------------> true;
- alert(aObj instanceof A); //----------------> true;
- //解决construtor的问题通常是让对象的constructor手动指向自己:
- aObj.constructor = A;//将自己的类赋值给对象的constructor属性
- alert(aObj.constructor === B);// -----------> flase;
- alert(aObj.constructor === A);//true
- //prototype
- alert(Object.prototype.toString.call(a) === '[object String]');//true;
- alert(Object.prototype.toString.call(b) === '[object Number]');//true;
- alert(Object.prototype.toString.call(c) === '[object Array]');//true;
- alert(Object.prototype.toString.call(d) === '[object Date]');//true;
- alert(Object.prototype.toString.call(e) === '[object Function]');//true;
- alert(Object.prototype.toString.call(f) === '[object Function]');//true;
2,编写一个js函数,时时显示当前时间,格式:“年-月-日 时:分:秒”
- function nowtime(){
- var nowDate = new Date();
- var year = nowDate.getFullYear();
- var month = nowDate.getMonth() + 1;
- var day = nowDate.getDate();
- var hours = nowDate.getHours();
- var minutes = nowDate.getMinutes();
- var second = nowDate.getSeconds();
- return year + '-' + month + '-' + day +' '+hours+':'+minutes +':'+second;
- }
- alert(nowtime());
3,显示隐藏dom元素
使用jquery
- $(function(){
- $("#div").show();
- $("#div").hide();
- });
4,如果添加HTML元素的事件处理,几种方法
1,直接元素中添加:
- <a href="###" onclick="fn();" >click</a>
2,找到dom节点如:
- var ob = document.getElementById("div");
- ob.onclick = function(){};
3,使用jquery添加静态的dom节点的事件
- $("#div").click(function(){});
- //动态生成的节点的话:
- $("#div").on("click",function(){});
- $("#div").live("click",function(){});
5,如何控制alert中的换行
- 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简单的面试题的更多相关文章
- js简单 图片版时钟,带翻转效果
js简单 图片版时钟,带翻转效果 <!DOCTYPE html> <html> <head> <meta charset="UTF-8"& ...
- js简单操作Cookie
贴一段js简单操作Cookie的代码: //获取指定名称的cookie的值 function getCookie(objName) { var arrStr = document.cookie.spl ...
- js简单弹出层、遮罩层
<html> <head> <title>js简单弹出层</title> <style> /*阴影边框效果*/ .box-shadow-1 ...
- Tourist.js – 简单灵活的操作指南和导航插件
Tourist.js 是一个基于 Backbone 和 jQuery 开发的轻量库,帮助你在应用程序创建简单易用的操作指南和导航功能.相比网站,它更适合用于复杂的,单页网站类型的应用程序.Touris ...
- js简单显示和隐藏div,触发超链接,动态更改button值,setInterval()简单使用,jquery easyui弹出框简单使用 .
js简单显示和隐藏div .<!DOCTYPE html> .<html> .<head> .<meta charset="UTF-8"& ...
- Gulp.js - 简单、直观的自动化项目构建工具
Gulp.js 是一个简单.直观的构建系统.崇尚代码优于配置,使复杂的任务更好管理.通过结合 NodeJS 的数据流的能力,你能够快速构建.通过简单的 API 接口,只需几步就能搭建起自己的自动化项目 ...
- Node.js简单介绍并实现一个简单的Web MVC框架
编号:1018时间:2016年6月13日16:06:41功能:Node.js简单介绍并实现一个简单的Web MVC框架URL :https://cnodejs.org/topic/4f16442cca ...
- JS简单入门教程
JS简单教程 使用方法:放到任意html页面的head标签下 Test1方法弹出当前时间对话框 Test2方法for循环输出 Test3方法for(…in…)输出数组内容 <script typ ...
- js简单实现链式调用
链式调用实现原理:对象中的方法执行后返回对象自身即可以实现链式操作.说白了就是每一次调用方法返回的是同一个对象才可以链式调用. js简单实现链式调用demo Object.prototype.show ...
随机推荐
- 英特尔和 Valve* 将英特尔® Embree 光线追踪技术添加至全新 Steam* Audio 插件
本文从英特尔® Embree 光线追踪技术着手,深入探讨英特尔与 Valve 合作带来的优势:一方面,开发人员使用英特尔高度优化的库创建场景,可以显著加快编译速度:另一方面,逼真的声效可以增强游戏性, ...
- 一、Unity Editor自定义菜单
官方文档:https://unity3d.com/cn/learn/tutorials/topics/interface-essentials/unity-editor-extensions-menu ...
- 《陪孩子像搭积木一样学编程》,一起来玩Scratch(1)使用Scratch编程的基本流程
编程是一件很有趣的事情.初次接触编程,你可能不知所措,别担心,这并不复杂.首先,为了让读者对编程有大概的了解,可以把编写Scratch程序的过程分成7个步骤(如图1.8).注意,这是理想状态.在实际的 ...
- 《Linux内核分析》第三周
[李行之原创作品 转载请注明出处 <Linux内核分析>MOOC课程http://mooc.study.163.com/course/USTC-1000029000] <Linux内 ...
- Feature List
我组最终决定所做的软件工程项目是Bing词典(UWP)的背单词模块,下面是初步定下的Feature List. 按用户场景变化顺序列举(假设是新用户): 1.用户可通过点击“背单词”标识或按钮进入背单 ...
- 组件 -- Alert
alert的背景色: alert-primary alert-secondary alert-success . . . .alert : 警告框类 .data-dismiss = "ale ...
- Alpha 冲刺一
团队成员 051601135 岳冠宇 051604103 陈思孝 031602629 刘意晗 031602248 郑智文 031602234 王淇 会议照片 项目燃尽图 项目进展 界面(简陋) 登录界 ...
- Ubuntu 14.04 installation & bugs on Alienware-13
列一下Alienware 13笔记本配置: Processor: Intel Core 5th Generation i5-5200U Processor (3M Cache, up to 2.70 ...
- Docker(九)-Docker创建Selenium容器
SeleniumHQ官方项目:https://github.com/seleniumHQ/docker-selenium 项目目前快速迭代中. Selenium 这里主要针对的是 Selenium G ...
- 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 ...