ECMAScript v1 v2 7- ASCII- UNICODE- . ECMAScript v3 UNICODE , , , .
JavaScript . . . ;, , .
, :
a=1;
b=3;
a=1
b=3
:
return
true
, :
return;
true;
return true;
Javascript C C++.
//
/*
*/
JavaScript 64- IEEE 754.
-9007199254740992 9007199254740992, .
:
(0, 234, 652345).
(0xF 1, 0xfe340b).
([][.][(|)[(+|_)]]).
. , , Infinity, NaN, Number.MAX_VALUE , .
String.
- Unicode- , (' ").
: \n, \b, \0, \xXX, \xXXXX .
:
str = "123" + "456"
length:
str.length
substring ( , ). - .
substr = str.substring(2,5);
indexOf s:
i = str.indexOf('a');
Javascript , .
var n = 10
str = n + " ";
str = n.toString() + " ";
, :
var n = 123456.789;
n.toFixed(0); // "123457"
n.toFixed(2); // "123456.79"
n.toExponential(1); // "1.2e+5"
n.toExponential(3); // "1.235e+5"
|
|
n.toPrecision(4); // "1.235e+5"
n.toPrecision(7); // "123456.8"
Javascript , .
:
var n = "12"*"2" // 24
:
var n = "12" + "2" // "122", +
Number(), , .
parseInt() parseFloat() , . , , NaN ( ).
parseInt(str, base) base- .
:
parseInt("3 "); // 3
parseFloat("3.14 "); // 3.14
parseInt("12.34"); // 12
parseInt("0xFF"); // 255
parseInt("11", 2); // 3 (1*2 + 1)
parseInt("ff", 16); // 255 (15*16 + 15)
parseInt("zz", 36); // 1295 (35*36 + 35)
parseInt("077", 8); // 63 (7*8 + 7)
parseInt("077", 10); // 77 (7*10 + 7)
true false boolean C++. .
:
if (a == 4)
b = b + 1;
else
a = a + 1;
= = = ( =), == ( =) , , :
if (a === "4") // !
b = b + 1;
if (a === 0) // 0
b = b + 1;
if (a == 0) // 0
b = b + 1;.
1. , x=5.
(x=5) | |||
x==8 x==5 | false true | ||
x==="5" x===5 | false true | ||
! = | x!=8 | true | |
!== | x!=="5" x!==5 | true false | |
> | x>8 | false | |
< | x<8 | true | |
>= | x>=8 | false | |
<= | x<=8 | true |
, :
if (condition) {
} else {
}
variablename=(condition)?value1:value2
switch(n)
{
case 1:
execute code block 1
break;
case 2:
execute code block 2
break;
default:
code to be executed if n is different from case 1 and 2
}
Javascript C/C++ for (item in list){...}.
for (i=0; i<5; i++) {
x=x + "The number is + i + <br />;
}
while (i<5) {
x=x + "The number is " + i + "<br />";
i++;
}
do {
x=x + "The number is " + i + "<br />";
|
|
i++;
} while (i<5);
var person={fname:"John",lname:"Doe",age:25};
for (x in person) { txt=txt + person[x]; }
Javascript :
function sum (a,b) // sum
{
return a+b;
}
, . a, b , !
:
var sum = function sum (a,b) { return a+b; };
sum , sum .
- , (properties) . , Javascript .
:
var point = new Object(); // !!!
point.x = 2.3; // x
point.y = 1.2; // y
:
point.x
:
point["x"]
. :
var point = { x:2.3, y:1.2 };
:
var rectangle = {
upperLeft: { x: 2, y: 2 }, lowerRight: { x: 4, y: 4 }
};
toString().
, , , , . Javascript , C. - Array().
, :
var a = new Array();
a[0] = 1.2;
a[1] = "JavaScript";
a[2] = true;
a[3] = { x:1, y:3 };
:
var a = new Array(1.2, "JavaScript", true, { x:1, y:3 });
:
var a = new Array(10);
- , . :
var a = [1.2, "JavaScript", true, { x:1, y:3 }];
:
var matrix = [[1,2,3], [4,5,6], [7,8,9]];
:
var base = 1024;
var table = [base, base+1, base+2, base+3];