freecodecamp JavaScript学习(-)
2017-05-17 14:11
671 查看
Understanding Uninitialized Variables
javascript变量未初始化时,初始值为underfined
如果对未初始化的变量进行加减乘除时,得到的值为:NaN,not a number
如果对为初始化的变量进行字符串拼接时,得到的值为一串字符串:“undefined”
Convert Celsius to Fahrenheit
var a = 1;
var b = ‘1’;
a == b; true
a != b ; false
a === b; flase
a !== b; true
js中”==”会先转换类型再进行比较两个变量的值;
“===”只有在相同类型下,才会比较其值,
需要注意的,JS会认为0 == ” ” ,返回值为true
“!=” 比较之前也会先转换类型
“!==” 比较之前不会先转换类型
“>”,”<”,比较之前也会先转换类型
Quoting Strings with Single Quotes:单引号‘’,双引号“”
可以使用反斜杠, 当你的字符串中需要显示“时
·
This is “quotes”.
当你的字符串中有很多双引号时,用反斜杠读写困难。
此时可以使用单引号,直接将含有双引号的字符串括起来
改写长如下:省略了反斜杠
Understand String Immutability
字符串中的字符不能单独更改,只能整体赋值更改。
==>
Word Blanks
https://en.wikipedia.org/wiki/Mad_Libs
Manipulate Arrays With push
-在数组最后加入
Manipulate Arrays With pop
-删除数组最后一个
Manipulate Arrays With shift
-删除数组第一个元素
Manipulate Arrays With unshift
-在数组前面加入元素
Global Scope and Functions
-全局变量
-当var变量定义在function外面,则为全局变量,整个脚本中都可以看见这个变量
-当变量定义是没有var,则自动成为全局变量,即使是定义在function中
Assignment with a Returned Value
golf :https://en.wikipedia.org/wiki/Golf
Selecting from many options with Switch Statements
case 是用“===”去判断条件是否为真的。
最后的default无需break。
javascript变量未初始化时,初始值为underfined
如果对未初始化的变量进行加减乘除时,得到的值为:NaN,not a number
如果对为初始化的变量进行字符串拼接时,得到的值为一串字符串:“undefined”
Convert Celsius to Fahrenheit
var a = 1;
var b = ‘1’;
a == b; true
a != b ; false
a === b; flase
a !== b; true
js中”==”会先转换类型再进行比较两个变量的值;
“===”只有在相同类型下,才会比较其值,
需要注意的,JS会认为0 == ” ” ,返回值为true
“!=” 比较之前也会先转换类型
“!==” 比较之前不会先转换类型
“>”,”<”,比较之前也会先转换类型
Quoting Strings with Single Quotes:单引号‘’,双引号“”
可以使用反斜杠, 当你的字符串中需要显示“时
·
var myStr=" This is \"quotes\"."·\;最后显示
This is “quotes”.
当你的字符串中有很多双引号时,用反斜杠读写困难。
此时可以使用单引号,直接将含有双引号的字符串括起来
var myStr = "<a href=\"http://www.example.com\" target=\"_blank\">Link</a>";
改写长如下:省略了反斜杠
var myStr = '<a href="http://www.example.com" target="_blank">Link</a>';
Understand String Immutability
字符串中的字符不能单独更改,只能整体赋值更改。
var myStr = "Bob"; myStr[0] = "J";
==>
var myStr = "Bob"; myStr= "Job";
Word Blanks
https://en.wikipedia.org/wiki/Mad_Libs
Manipulate Arrays With push
-在数组最后加入
var arr = [1,2,3]; arr.push(4); // arr is now [1,2,3,4]
Manipulate Arrays With pop
-删除数组最后一个
var oneDown = [1, 4, 6].pop(); //oneDown is now [1, 4]
Manipulate Arrays With shift
-删除数组第一个元素
var myArray = [["John", 23], ["dog", 3]]; removedFromMyArray=myArray.shift(); //removedFromMyArray is now [["dog", 3]]]
Manipulate Arrays With unshift
-在数组前面加入元素
// Example var ourArray = ["Stimpson", "J", "cat"]; ourArray.shift(); // ourArray now equals ["J", "cat"] ourArray.unshift("Happy"); // ourArray now equals ["Happy", "J", "cat"]
Global Scope and Functions
-全局变量
-当var变量定义在function外面,则为全局变量,整个脚本中都可以看见这个变量
-当变量定义是没有var,则自动成为全局变量,即使是定义在function中
Assignment with a Returned Value
golf :https://en.wikipedia.org/wiki/Golf
Selecting from many options with Switch Statements
switch (num) { case value1: statement1; break; case value2: statement2; break; ... case valueN: statementN; break; default: defaultStatement; }
case 是用“===”去判断条件是否为真的。
最后的default无需break。
相关文章推荐
- freecodecamp JavaScript学习(三)
- JavaScript学习——freeCodeCamp(1)
- freecodecamp JavaScript学习(四)
- freecodecamp学习--Find the Longest Word in a String
- FreeCodeCamp学习--Title Case a Sentence
- FreeCodeCamp学习--Chunky Monkey
- FreeCodeCamp学习--Seek and Destroy
- FreeCodeCamp学习--Mutations
- FreeCodeCamp学习--Check for Palindromes
- FreeCodeCamp学习--Repeat a string repeat a string
- FreeCodeCamp学习--Slasher Flick
- FreeCodeCamp学习--Truncate a string
- FreeCodeCamp学习--Seek and Destroy
- FreeCodeCamp学习--Title Case a Sentence
- FreeCodeCamp学习--Return Largest Numbers in Arrays
- FreeCodeCamp学习--Slasher Flick
- FreeCodeCamp(一)学习笔记
- FreeCodeCamp学习--Confirm the Ending
- [FreeCodeCamp-JavaScript]Basic Algorithm
- FreeCodeCamp学习--Falsy Bouncer