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 ...
随机推荐
- 关于App自动化执行链接Appium服务包名正确但是报错An unknown server-side error occurred while processing the command
在执行链接Appium服务时连接失败可能原因: 1.报错截图: 2.先检查包名是否正确(正常情况下包名不会错误)通过命令行查看包名:aapt dump badging xxx.apk 3.检查对应包的 ...
- Yaml学习文档
pdf文档地址 http://yaml.org/spec/ JS-Yaml demo地址 http://nodeca.github.io/js-yaml/
- anoconda 神经网络 相关操作
1. conda 相关操作 建立新环境:conda crearte -n NewName python=版本(3.6) 激活环境:conda activate NewName 关闭环境:conda d ...
- HyperLedger/Fabric SDK使用Docker容器镜像快速部署上线
HyperLedger/Fabric SDK Docker Image 该项目在github上的地址是:https://github.com/aberic/fabric-sdk-container ( ...
- WebShell代码分析溯源(第1题)
<?php $POST['POST']='assert';$array[]=$POST;$array[0]['POST']($_POST['assert']);?> assert,是php ...
- Linux读书笔记第五章
主要内容: 什么是系统调用 Linux上的系统调用实现原理 一个简单的系统调用的实现 1. 什么是系统调用 简单来说,系统调用就是用户程序和硬件设备之间的桥梁. 用户程序在需要的时候,通过系统调用来使 ...
- Mac用户抓包软件Charles 4.0 破解 以及 抓取Https链接设置
相信大家曾经都是Window的用户,作为前端哪能没有一款抓包工具,抓包工具可以非常便捷的帮助我们分析接口返回报文数据,快速定位问题. 曾经横扫window用户的Fiddler便是我们的挚爱,然而,作为 ...
- jvm垃圾回收机制和常见算法
这是朋友给的面试题里边的,具体地址已经找不到,只能对原作者说声抱歉了: 理论上来讲sun公司只定义了垃圾回收机制规则,而步局限于其实现算法,因此不同厂商生产的虚拟机采用的算法也不尽相同. GC(Gar ...
- ElasticSearch 2 (21) - 语言处理系列之单词识别
ElasticSearch 2 (21) - 语言处理系列之单词识别 摘要 一个英语单词相对容易识别:因为英语单词是被空格或(某些)标点符号隔开的.但在英语中也有反例:you're 这个词是一个单词还 ...
- 在ubuntu下运行python脚本
转自http://www.cnblogs.com/hester/p/5575658.html 1. 运行方式一 新建test.py文件: 1 touch test.py 然后vim test.py打开 ...