iT邦幫忙

2021 iThome 鐵人賽

DAY 13
0

Data: Number, String, Boolean

  • Number: e.g. 7, 17
  • String: consist of quotation marks and semicolon, e.g. “this is a string”;
  • Boolean: e.g. true, false

Variables

A variable is a container for storing data or values.
*Please note that it displays as the order we code.

Example

var x; → let's declare the variable as x.
x=17; → and we start to store value into the variable. 
alert(x); 
x="value";
alert(x);
var y=true;

Operators

Operators is like math formulas, consisting of various characters.
Let’s explain the formulas and terms by examples...

When we write

3+5; → Arithmetic operators
alert(3+5);

=> The result is 8.

var result=3*5; → Assignment operators
alert(result);

=> The result is 15.

Follow the last operator

result++; → increment (++) operators. It means the result has to plus 1, which can also be written as “result+1;”
alert(result);

=> The result is 16.

4<3; → Comparison operators.
result=4<3; 
alert(result);

=> The boolean is “true.” If we write 4<3, the boolean is “false.”

var data=3;
result=data*data;
alert(result);

=> The result is 9.

alert(data);

=> The result is 3.


Music of Today: 酒鬼 Lasang Bastard by 張震嶽 ayal komod

Yes


Like/Share/Follow

Feel free to comment and share your ideas below to learn together!
If you guys find this article helpful, please kindly do the writer a favor — LIKE this article./images/emoticon/emoticon12.gif


上一篇
#12 JavaScript Introduction
下一篇
#14 JS: create a calculator by prompt()
系列文
Learn & Play JavaScript -- Entry-Level Front-End Web Development30
圖片
  直播研討會
圖片
{{ item.channelVendor }} {{ item.webinarstarted }} |
{{ formatDate(item.duration) }}
直播中

尚未有邦友留言

立即登入留言