var x;
x=
0;
x;
x=
1;
x=
0.01;
x=
"Hello World";
x=
'JavaScript';
x=
true;
x=
false;
x=
null;
x=
undefined;
var book={topic:
"JavaScript",fat:
true};
book.topic;
book[
"fat"];
book.author=
"Flanagan";
book.contents={};
var primes=[
2,
3,
5,
7];
primes[
0];
primes.length;
primes[primes.length-
1];
primes[
4]=
9;
primes[
4]=
11;
var empty=[];
empty.length;
var points=[
{x:
0,y:
0},
{x:
1,y:
1}
]
var data={
trial1:[[
1,
2],[
3,
4]],
trial2:[[
2,
3],[
4,
5]]
}
3+
2
3-
2
3*
2
3/
2
points[
1].x-points[
0].x;
"3"+
"2"
var count=
0;
count++;
count--;
count+=
2;
count*=
3;
count
var x=
2,
var y=
3;
x==y;
x!=y;
x<y;
x<=y;
x>y;
x>=y;
"two"==
"three";
"two">
"three";
false==(
"two"==
"three");
(x==
2)&&(y==
3);
(x>
3)||(y<
3);
!(x==y);
function plus1(x){
return x+
1
}
var square=
function(x){
return x*x;
};
square(plus1(y));
var a=[]
a.push(
1,
2,
3);
a.reverse();
points.dist=
function(){
var p1=
this[
0];
var p2=
this[
1];
var a=p2.x-p1.x
var b=p2.y-p1.y
return Math.sqrt(a*a+b*b)
}
points.dist()
function abs(x){
if(x>
0){
return x;
}
else{
return -x;
}
}
function factorial(n){
var product=
1;
while(n>
1){
product*=n;
n--;
}
return product;
}
factorial(
4);
function factorial2(n){
var i;product=
1
for(i=
2;i<=n;i++){
product*=i;
}
return product;
}
factorial(
5);
function Point(x,y){
this.x=x;
this.y=y;
}
var p=
new Point(
1,
1);
Point.prototype.r=
function(){
return Math.sqrt(
this.x*
this.x+
this.y*
this.y
);
}
p.r()
转载请注明原文地址: https://ju.6miu.com/read-970364.html