Javascript 学习第一天

本文介绍了JavaScript中的六种基本数据类型:数字、字符串、布尔值、对象、函数和未定义值。详细解释了每种类型的使用特点及注意事项,并通过示例说明了如何进行变量比较和类型转换。

There are six basic types of values in JavaScript numbers, strings, Booleans, objects, functions, and undefined values.

**Number : > 粗体 Notice 2.998e8 ** scientific notation “e” (for “exponent”) 2.998 × 10^8 = 299,800,000.

print == console.log(typeof "x")

JavaScript has a Boolean type, which has just two values: true and false

0 == false and "" == false are also true === and !==.

The first tests whether a value is precisely equal to the other. the second tests whether it is not precisely equal.

Logical operators

console.log(8 * null)
// → 0
console.log("5" - 1)
// → 4
console.log("5" + 1)
// → 51
console.log("five" * 2)
// → NaN
console.log(false == 0)
// → true

Function

  • alert("Good morning!");
  • The console.log function
console.log("the value of x is", x);
// → the value of x is 30
  • prompt and confirm confirm("Shall we, then?"); . This returns a Boolean: true if the user clicks OK false if the user clicks Cancel.

Control flow

if (num < 10)
  alert("Small");
else if (num < 100)
  alert("Medium");
else
  alert("Large");

Defining a function

var square = function(x) {
  return x * x;
};

console.log(square(12));
// → 144

The function body must always be wrapped in braces, even when it consists of only a single statement

js array vs python list

push == append

var mack = [];
mack.push("Mack");
mack.push("the", "Knife");
console.log(mack);
// → ["Mack", "the", "Knife"]
console.log(mack.join(" "));
// → Mack the Knife
console.log(mack.pop());
// → Knife

转载于:https://my.oschina.net/pythonnnn/blog/675446

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值