1 下面列出的值被当作假

false

null

undefined

''

0

NaN

其它所有值被当作是真

console.log(undefined || true); //true

console.log(0||true); //true

console.log(''||true); //true

console.log(false||true); //true

console.log(null||true); //true

console.log(NaN||true); //true

console.log(undefined&&true); //undefined

console.log(0&&true); //0

console.log(null&&true); //null

console.log(' '&&true); //空字符串

console.log(NaN&&true); //NaN

console.log(false&&true); //false

console.log(undefined || 0); //0

console.log(0||undefined); //undefined

console.log(''== 0);//true

console.log(''== '0');//false

console.log(0=='0')//true

console.log(false=='false')//false

console.log(false==false);//true

console.log('false'=='false');//true

console.log(false=='0');//true

console.log(false==null);//false

console.log(false==undefined);//false

console.log(null==undefined);//true

2 javascript 5种简单数据类型

Undefined 类型

Boolean 类型

Number 类型

String类型

Object 类型

var a = new Number();

var c = new Boolean();

var d = undefined;

var e = new String();

var f = new Object();

console.log(a,b,c,d,e,f);//Number {}Boolean {} undefined String {}Object {}

3 typeof操作符

“undefined”    ----------   如果值未定义                       Undefined

“boolean”      ----------     如果这个值是布尔值              Boolean

“string”        ----------     如果这个值是字符串              String

“number”      ----------     如果这个值是数值类型           Number

“object”        ----------     如果这个值是对象或null        Object

“function” ----------     如果这个值是函数                 Function

var a = null;

var b ='';

var c =0;

var d = [1,2];

var c = function(){}

var e = false;

var f;

console.log(typeof a,typeof b,typeof c,typeof d,typeof e,typeof f); //object string function object boolean undefined

4 运算符优先级

5 函数调用模式(4种)

(1)方法调用模式

当一个函数被保存为对象的一个属性时,称它为一个方法

var person = {

say:function(){

alert('hi!');

}

}

person.say();

(2)函数调用模式

当一个函数并非一个对象的属性时,那么它被当作一个函数来调用

function say(){

alert('hi!');

}

var a= say();

(3)构造器调用模式

function Person(){

this.say = function(){

alert('hi');

}

}

var p = new Person();

(4)call/apply调用模式

var arr = [1,2];

function add(){

return arguments[0]+arguments[1];

}

var sum = add.apply(null,arr);

console.log(sum);//3

6 return语句

如果没有return时,函数默认返回undefined,如果用构造器调用模式,则返回函数的this对象。

var add = function(a,b){

a+b;

}

console.log(add()); //返回undefined

var a = new add();

console.log(a);// 返回this对象

7 try/catch语句

try{

console.log(abc);

}catch(e){

console.log(e.name+":"+e.message); //ReferenceError:abc is not defined

}

8 闭包

下面这种情况,得到的值都是5

var arr =[];

for(var i=0;i<5;i++){

arr[i] = function(){

console.log(i);

};

}

arr[0](); //5

arr[1](); //5

arr[2](); //5

arr[3](); //5

arr[4](); //5

解决方法

var arr =[];

for(var i=0;i<5;i++){

(function(i){

arr[i] = function(){

console.log(i);

};

}(i))

}

arr[0](); //0

arr[1](); //1

arr[2](); //2

arr[3](); //3

arr[4](); //4

javascript基础知识拾遗的更多相关文章

  1. Javascript基础知识总结一

    Javascript基础知识总结一 <!DOCTYPE html> <html> <head lang="en"> <meta chars ...

  2. 学习javascript基础知识系列第二节 - this用法

    通过一段代码学习javascript基础知识系列 第二节 - this用法 this是面向对象语言中的一个重要概念,在JAVA,C#等大型语言中,this固定指向运行时的当前对象.但是在javascr ...

  3. 学习javascript基础知识系列第三节 - ()()用法

    总目录:通过一段代码学习javascript基础知识系列 注意: 为了便于执行和演示,建议使用chrome浏览器,按F12,然后按Esc(或手动选择)打开console,在console进行执行和演示 ...

  4. JavaScript 基础知识 - BOM篇

    前言 本篇文章是JavaScript基础知识的BOM篇,如果前面的<JavaScript基础知识-DOM篇>看完了,现在就可以学习BOM了. 注意: 所有的案例都在这里链接: 提取密码密码 ...

  5. (转)JAVA AJAX教程第二章-JAVASCRIPT基础知识

    开篇:JAVASCRIPT是AJAX技术中不可或缺的一部分,所以想学好AJAX以及现在流行的AJAX框架,学好JAVASCRIPT是最重要的.这章我给大家整理了一些JAVASCRIPT的基础知识.常用 ...

  6. JavaScript基础知识整理

    只整理基础知识中关键技术,旨在系统性的学习和备忘. 1.在 JScript 中 null 和 undefined 的主要区别是 null 的操作象数字 0,而 undefined 的操作象特殊值NaN ...

  7. Jquery源码中的Javascript基础知识(三)

    这篇主要说一下在源码中jquery对象是怎样设计实现的,下面是相关代码的简化版本: (function( window, undefined ) { // code 定义变量 jQuery = fun ...

  8. JavaScript基础知识从浅入深理解(一)

    JavaScript的简介 javascript是一门动态弱类型的解释型编程语言,增强页面动态效果,实现页面与用户之间的实时动态的交互. javascript是由三部分组成:ECMAScript.DO ...

  9. JavaScript基础知识必知!!!

    JavaScript一种直译式脚本语言,是一种动态类型.弱类型.基于原型的语言,内置支持类型. JS作用:表单验证,减轻服务端的压力:添加页面动画效果:动态更改页面内容:Ajax网络请求. 下面简单介 ...

随机推荐

  1. 【转载】kafka的工作原理

    http://www.ibm.com/developerworks/cn/opensource/os-cn-kafka/index.html 消息队列 消息队列技术是分布式应用间交换信息的一种技术.消 ...

  2. codeforces 480A A. Exams(贪心)

    题目链接: A. Exams time limit per test 1 second memory limit per test 256 megabytes input standard input ...

  3. 让input框只能输入数字

    var oInput = document.querySelector("input");oInput.onkeyup = function () { var value = th ...

  4. D - Palindrome Partitioning (DP)

    Description A palindrome partition is the partitioning of a string such that each separate substring ...

  5. Entity Framework版本历史概览

    转自:http://www.cnblogs.com/fecktty2013/archive/2014/09/26/entityframework-overview.html EF版本 .net fra ...

  6. python socket发送魔法包网络唤醒开机.py

    python socket发送魔法包网络唤醒开机.py 现在的电脑应该都普遍支持有线网络的WOL了,支持无线网络唤醒的电脑,可能比较少. """ python socke ...

  7. NET Memory Profiler 跟踪.net 应用内存

    NET Memory Profiler 跟踪.net 应用内存 用 .NET Memory Profiler 跟踪.net 应用内存使用情况--基本应用篇 作者:肖波      .net 框架号称永远 ...

  8. Contains Duplicate

    Given an array of integers, find if the array contains any duplicates. Your function should return t ...

  9. QT QT程序初练

    //界面编程#include "widget.h" #include "ui_widget.h" Widget::Widget(QWidget *parent) ...

  10. Linux Linux程序练习十一(网络编程大文件发送UDP版)

    //网络编程发送端--大文件传输(UDP) #include <stdio.h> #include <stdlib.h> #include <string.h> # ...