javascript 1
6806 ワード
<script>
// :
// “.” “[]” 。
var book={
topic:'javascript',
fat:true
}
console.log(book.topic);//javascript
console.log(book['fat']);//true
console.log(book.author);//undefind
book.author='Flanagan';
book.contents={};
console.log(book['contents']);//Object{}
var primes=[2,3,5,7];
console.log(primes[0]);//2
console.log(primes.length);//4
console.log(primes[primes.length-1]);//7
primes[4]=9;
primes[4]=11;
var empty=[];
console.log(empty.length);//0
var points=[
{x:0,y:0},
{x:1,y:1}
]
var data={
trial1:[[1,2],[3,4]],
trial2:[[2,3],[4,5]]
}
//var count=0;
//count++; 1
//count+=2; 2; "count=count+2"
//count
// 、 、 true false
console.log("two"=="three")//false
console.log("two">"th")//true,"tw" "th"
//console.log(false==(x<y))//true,false false
//
//console.log((x==2)&&(y==3))//true, true,&& “ ”
//console.log((x>3)||(y<3))//false, true,|| “ ”
//console.log(!(x==y))//true"!"
// :
// ,
// ( ),
function plus1(x){
return x+1;
};
console.log(plus1(3))//4
var square=function(x){
return x*x;
};
console.log(square(plus1(3)))
// javascript ,
// , ” “
// / ,
// , “ ”, javascript
var a=[];
a.push(1,2,3,4);//push
a.reverse();//
console.log(a);
// ,“this”
points.dist=function(){//
var p1=this[0];// this
var p2=this[1];
var a=p2.x-p1.x;//x
var b=p2.y-p1.y;
return Math.sqrt(a*a+b*b)//
}
console.log(points.dist())//
</script>