/* 函数声明 */
foo(); // "bar"
function foo() {
console.log("bar");
}
/* 函数表达式 表达式定义的函数,成为匿名函数。匿名函数没有函数提升。*/
baz(); // TypeError: baz is not a function
//此时的"baz"相当于一个声明的变量,类型为undefined。
由于baz只是相当于一个变量,因此浏览器认为"baz()"不是一个函数。
var baz = function() {
console.log("bar2");
};
const MY_OBJECT = {"key": "value"};
MY_OBJECT.key = "otherValue";
x = "The answer is " + 42 // "The answer is 42" y = 42 + " is the answer" // "42 is the answer"
"37" - 7 // 30 "37" + 7 // "377"
"1.1" + "1.1" = "1.11.1" (+"1.1") + (+"1.1") = 2.2 // 注:加入括号为清楚起见,不是必需的。
var unusualPropertyNames = {
"": "An empty string",
"!": "Bang!"
}
console.log(unusualPropertyNames.""); // 语法错误: Unexpected string
console.log(unusualPropertyNames[""]); // An empty string
console.log(unusualPropertyNames.!); // 语法错误: Unexpected token !
console.log(unusualPropertyNames["!"]); // Bang!
var foo = {a: "alpha", 2: "two"};
console.log(foo.a); // alpha
console.log(foo[2]); // two
//console.log(foo.2); // Error: missing ) after argument list
//console.log(foo[a]); // Error: a is not defined
console.log(foo["a"]); // alpha
console.log(foo["2"]); // two
var obj = {
// __proto__
__proto__: theProtoObj,
// Shorthand for ‘handler: handler'
handler,
// Methods
toString() {
// Super calls
return "d " + super.toString();
},
// Computed (dynamic) property names
[ 'prop_' + (() => 42)() ]: 42
};
// 引号转义 var quote = "He read /"The Cremation of Sam McGee/" by R.W. Service."; // 转义反斜线 var home = "c://temp"; // 转义换行 一条语句拆成多行书写 var str = "this string / is broken / across multiple/ lines." console.log(str); // this string is broken across multiplelines. // Javascript没有“heredoc”语法,但可以用行末的换行符转义和转义的换行来近似实现 var poem = "Roses are red,/n/ Violets are blue./n/ I'm schizophrenic,/n/ And so am I."
机械节能产品生产企业官网模板...
大气智能家居家具装修装饰类企业通用网站模板...
礼品公司网站模板
宽屏简约大气婚纱摄影影楼模板...
蓝白WAP手机综合医院类整站源码(独立后台)...苏ICP备2024110244号-2 苏公网安备32050702011978号 增值电信业务经营许可证编号:苏B2-20251499 | Copyright 2018 - 2025 源码网商城 (www.ymwmall.com) 版权所有