null and undefined in javascript

> var un;
> console.log(un);
undefined
> var nu = null;
> console.log(nu);
null
> typeof un
'undefined'
> typeof nu
'object'
> un == nu
true
> un === nu
false
> Number(undefined)
NaN
> Number(null)

undefined表示”缺少值”,就是此处应该有一个值,但是还没有定义。典型用法是:
(1)变量被声明了,但没有赋值时,就等于undefined。
(2) 调用函数时,应该提供的参数没有提供,该参数等于undefined。
(3)对象没有赋值的属性,该属性的值为undefined。
(4)函数没有返回值时,默认返回undefined。

挑战最强大脑——来自全球的14个编码社区

史蒂夫·乔布斯说过,每个人都应该学习给电脑编写程序的技术,因为这一过程能够教你如何去思考!众所周知,编程已成为开发者生命中至关重要的一部分。很多事实表明,越来越多的人不管男女老少都将参与编程这个行业。

?

学习编程的渠道有很多种,比如你可以利用一些互动平台或者书籍去学习编程,无论是哪种,只要找到适合自己的就OK。俗话说,光说不练嘴把式,因此,我们还需要进行实践。

编程极富有创造性,你可以创造出许多新奇有趣的想法。很多时候,开发者在相同的问题上花费了大量时间,而忽略了创造性。笔者不能确定这是否是许多网站发起编程挑战赛的原因,但可以确定的是,这些挑战对于开发者而言是有很大帮助的。它的好处在于:

  • 思考问题有新的思维方式;
  • 学到一门新语言;
  • 提升解决方法的能力;
  • 激发大脑灵感、专注;
  • 有趣!

文中搜集了14个不错的学习资源,帮助你挑战自我,领略并探索计算机领域无穷奥秘。

1.?[topcoder]

[topcoder]社区得到了数百万编码者的支持,因此你可以了解到很多挑战性的项目,基于此你还可以为自己赚去额外的报酬。你可以每天或每周参与编码挑战,该社区提供的项目极具有挑战性,对于初学者而言有一定的难度,但却值得一试。

2.?HackerEarth

HackerEarth提供了SaaS应用,能够为应试者自动评估技术和逻辑技能。此外,它还可作为人才聚集地,为公司提供智能招聘服务资源,帮助公司挑选适宜人才。

HackerEarth会频繁更新挑战项目,你可以提前几周登记注册,事先了解下项目,为挑战做好充足的准备。

3.?Coderbyte

Coderbyte旨在帮助提高开发者的编程技能,其得到了初学者和中级程序员的一致好评。该项目由Daniel Borowski?于2012年推出,现今任何开发者都可利用业余时间进行维护。

如果你遇到难题,你可以在Coderbyte上提问,该社区的用户相当活跃,你可以获得任何你想要的答案。

4.?Project Euler

Project Euler可能是全球最流行的编程挑战网站,项目推出初期就拥有几十万的用户,足以表明其影响力有多大。Project Euler致力于鼓励、挑战并且发展解题技巧,并为那些对迷人的数学世界有兴趣的人提供乐趣。

你可以通过:Wikipedia?、?Reddit?、?Stack Overflow?以及Google Code?了解更多Project Euler相关信息。

5.?Daily Programmer

如果你想了解更多关于编程和问题解答,那么Reddit Daily Programmer就是你的好去处。毋庸置疑,许多开发者都喜欢在Reddit上查看新闻、探讨话题。你的每一次创建、评论,社区成员都审阅并提交,所以你可能会获得许多意见和答案,直至满足你的需求。

6.?Codility Train

Codility Train支持多种语言,你可以预先定制或预先思考挑战项目,根据难易度进行分类,当然挑战何种程度取决于你自己的选择。

每项编程挑战最后都有详细的解释,挑战时间也有限制并不是绝对的自由。

7.?SPOJ

Sphere Online Judge?是一个由成千上万个编码挑战项目组成的社区,它几乎支持所有的编程语言,你还可以基于该社区论坛需求帮助

npm设置代理

无密码的:

$ npm config set proxy http://server:port
$ npm config set https-proxy http://server:port

有密码的

$ npm config set proxy http://username:password@server:port
$ npm config set https-proxy http://username:pawword@server:port

删除代理

npm config rm proxy
npm config rm https-proxy

在AngularJS的使用$apply更新model

先看一个不能work的

如果ng-app和ng-controller写在一个dom里,这样就不能更新model里的值
分开写就没问题
解决这个问题可以这样:

当然也可以这样:

function Ctrl($scope) {
  $scope.message = "Waiting 2000ms for update";
    setTimeout(function () {
        $scope.message = "Timeout called!";
        $scope.$apply();
    }, 2000);
}

Check if Function Exists Before Calling

When using scripts that are shared between different areas of a site, there may be cases where a function is called that doesn’t exist. It makes sense on one page (the dependency is there) but not another. The difference is too slight to warrant forking the file into different versions. Instead, you can just check if the function exists before calling it to avoid the error:

The text, ntext, and image data types cannot be compared or sorted, except when using IS NULL or LIKE operator.

Error Message

Server: Msg 306, Level 16, State 1, Line 1
The text, ntext, and image data types cannot be compared
or sorted, except when using IS NULL or LIKE operator.

Causes

NTEXT data types are used for variable-length of Unicode data, TEXT data types are used for variable-length non-Unicode data while IMAGE data types are used for variable-length binary data.

One way of getting this error is when including a column of TEXT, NTEXT or IMAGE data type in the ORDER BY clause. To illustrate, here’s a script that will generate this error message:

CREATE TABLE [dbo].[BookSummary] (
    [BookSummaryID]     INT NOT NULL IDENTITY(1, 1),
    [BookName]          NVARCHAR(200),
    [Author]            NVARCHAR(100),
    [Summary]           NTEXT
)
SELECT * FROM [dbo].[BookSummary]
ORDER BY [Summary]
Msg 306, Level 16, State 2, Line 2
The text, ntext, and image data types cannot be compared or sorted,
except when using IS NULL or LIKE operator.

Another way of getting this error is including a column of TEXT, NTEXT or IMAGE data type as part of a GROUP BY clause, as can be seen in the following script:

SELECT [Summary], COUNT(*)
FROM [dbo].[BookSummary]
GROUP BY [Summary]
Msg 306, Level 16, State 2, Line 3
The text, ntext, and image data types cannot be compared or sorted,
except when using IS NULL or LIKE operator.

Note that ntext, text and image data types will be removed in a future version of SQL Server and usage of these data types should be avoided. When using SQL Server 2005 or later, use nvarchar(max), varchar(max) and varbinary(max), respectively, instead.

Solution / Workaround:

To work around this error, the TEXT or NEXT column needs to be converted to VARCHAR or NVARCHAR when used in either the ORDER BY clause or the GROUP BY clause of a SELECT statement.

In the first example, using SQL Server 2000, the NTEXT column can be converted to NVARCHAR(4000) in the ORDER BY clause to avoid the error and generate the result desired:

SELECT * FROM [dbo].[BookSummary]
ORDER BY CAST([Summary] AS NVARCHAR(4000))

Using SQL Server 2005 or SQL Server 2008 (or later), instead of NVARCHAR(4000), the NTEXT column can be converted to NVARCHAR(MAX):

SELECT * FROM [dbo].[BookSummary]
ORDER BY CAST([Summary] AS NVARCHAR(MAX))

As for the second example, using SQL Server 2000, the same can be done with the NTEXT column in the GROUP BY clause to avoid the error:

SELECT CAST([Summary] AS NVARCHAR(4000)) AS [Summary], COUNT(*)
FROM [dbo].[BookSummary]
GROUP BY CAST([Summary] AS NVARCHAR(4000))

Using SQL Server 2005 or SQL Server 2008 (or later), instead of NVARCHAR(4000), the NTEXT column can be converted to NVARCHAR(MAX):

SELECT CAST([Summary] AS NVARCHAR(MAX)) AS [Summary], COUNT(*)
FROM [dbo].[BookSummary]
GROUP BY CAST([Summary] AS NVARCHAR(MAX))

To totally avoid getting this error message, if using SQL Server 2005 or SQL Server 2008, it is suggested that any TEXT, NTEXT or IMAGE data types be converted to VARCHAR(MAX), NVARCHAR(MAX) and VARBINARY(MAX), respectively.