| [ Web Proxy ] |
| Viewing: https://developer.mozilla.org/ru/docs/Web/JavaScript/Guide/Grammar_and_types#unicode | [Back] [Original] |
Get to know MDN better
This page was translated from English by the community. Learn more and join the MDN Web Docs community.
, , .
JavaScript Java, , Awk, Perl Python.
JavaScript Unicode. , Frh ("" -) .
var Frh = "foobar";
, frh Frh JavaScript .
JavaScript statements (;). (space), (tab) (newline) (whitespace). JavaScript , (tokens), , , . ECMAScript (ASI), (statements). , , . , Lexical Grammar.
, C++ :
// , .
/* ,
.
*/
/* /* */ SyntaxError */
JavaScript :
. identifiers .
JavaScript , (_) ($); (0-9). JavaScript , "A" "Z" ( ) "a" "z" ( ).
ISO 8859-1 Unicode, , . Unicode .
: Number_hits, temp99, _name.
:
var. , var x = 42. , .x = 42. , , . (strict mode). .let. , let y = 13. ., var let , undefined.
var a;
console.log("The value of a is " + a); // a undefined
console.log("The value of b is " + b); //Uncaught ReferenceError: b
console.log("The value of c is " + c); // c undefined
var c;
console.log("The value of x is " + x); //Uncaught ReferenceError: x
let x;
undefined, , . input , if true:
var input;
if (input === undefined) {
doThis();
} else {
doThat();
}
undefined false, . , myFunction, .. myArray :
var myArray = [];
if (!myArray[0]) {
myFunction();
}
undefined NaN, :
var a;
a + 2; // NaN
null 0 false :
var n = null;
console.log(n * 32); // 0
, , .. . , , .. .
ECMAScript 6 JavaScript ; , , _ _( ), . , 5, .. x ( ), x, , if:
if (true) {
var x = 5;
}
console.log(x); // 5
, let, ECMAScript 6:
if (true) {
let y = 5;
}
console.log(y); // ReferenceError
JavaScript , , , . (hoisting) ; JavaScript . , , , undefined:
/*
* Example 1
*/
console.log(x === undefined); // true
var x = 3;
/*
* Example 2
*/
var myvar = "my value";
(function () {
console.log(myvar); // undefined
var myvar = "local value";
})();
, :
/*
* Example 1
*/
var x;
console.log(x === undefined); // true
x = 3;
/*
* Example 2
*/
var myvar = "my value";
(function () {
var myvar;
console.log(myvar); // undefined
myvar = "local value";
})();
- , var , . .
ECMAScript 2015, let (const) . , ReferenceError. " " , .
function do_something() {
console.log(foo); // ReferenceError
let foo = 2;
}
: , , .
/* */
foo(); // "bar"
function foo() {
console.log("bar");
}
/* */
baz(); // TypeError: baz is not a function
var baz = function () {
console.log("bar2");
};
. - window, , window.variable:
window.foo = "bar";
, , window frame window frame, window frame. , phoneNumber , iframe parent.phoneNumber.
, , const. , : , $ , .
const PREFIX = "212";
. .
, , , , let. const , .
, . TypeError:
//
function f() {}
const f = 5;
//
function f() {
const g = 5;
var g;
// -
}
, ,
const MY_OBJECT = { key: "value" };
MY_OBJECT.key = "otherValue";
ECMAScript :
JavaScript . , , , . , , :
var answer = 42;
, :
answer = "Thanks for all the fish...";
JavaScript , .
, +, JavaScript . :
x = "The answer is " + 42; // "The answer is 42"
y = 42 + " is the answer"; // "42 is the answer"
JavaScript . :
"37" - 7; // 30
"37" + 7; // "377"
, , , , :
parseInt . ( radix).
" ":
"1.1" + "1.1"; // "1.11.1"
(+"1.1") + (+"1.1"); // 2.2
// , .
JavaScript. , . :
, , ( [] ). , , , , .
coffees , :
var coffees = ["French Roast", "Colombian", "Kona"];
, JavaScript , , . , , , , .
Array. , Array .
array. , undefined. :
var fish = ["Lion", , "Angel"]; // ["Lion", undefined, "Angel"]
2 (fish[0] - "Lion", fish[1] - undefined, fish[2] - "Angel").
, . , 3. myList[3]. .
: , .
var myList = ["home", , "school", ]; // ["home", undefined, "school"]
, myList[0] myList[2] undefined:
var myList = [, "home", , "school"]; // [undefined, "home", undefined, "school"]
, myList[1] myList[3] undefined. .
var myList = ["home", , "school", ,]; // ["home", undefined, "school", undefined]
JavaScript . , , , undefined .
(Boolean) : true false.
true false true false Boolean. Boolean - . , Boolean.
, , .
:
0, 117 -345 ( ) 015, 0001 -077 ( ) 0x1123, 0x00111 -0xF1A7 ( ) 0b11, 0b0011 -0b11 ( )
:
"e" "E", , . , "e" ( "E").
:
[(+|-)][digits][.digits][(E|e)[(+|-)]digits]
:
3.14 -3.1E+12 -.3333333333333333333 .1e-23
, , ( {} ). , .. , , "{" .
myCar car "Saturn", getCar CarTypes("Honda"), special Sales:
var Sales = "Toyota";
function CarTypes(name) {
if (name == "Honda") {
return name;
} else {
return ", " + name + ".";
}
}
var car = { myCar: "Saturn", getCar: CarTypes("Honda"), special: Sales };
console.log(car.myCar); // Saturn
console.log(car.getCar); // Honda
console.log(car.special); // Toyota
, . :
var car = { manyCars: { a: "Saab", b: "Jeep" }, 7: "Mazda" };
console.log(car.manyCars.b); // Jeep
console.log(car[7]); // Mazda
, . JavaScript , . ( [] ), ( . ):
var unusualPropertyNames = {
"": "An empty string",
"!": "Bang!"
}
console.log(unusualPropertyNames.""); // SyntaxError: Unexpected string
console.log(unusualPropertyNames[""]); // "An empty string"
console.log(unusualPropertyNames.!); // SyntaxError: Unexpected token !
console.log(unusualPropertyNames["!"]); // "Bang!"
ES2015 foo: foo, , . , , .
var obj = {
// __proto__
__proto__: theProtoObj,
// handler: handler
handler,
//
toString() {
//
return "d " + super.toString();
},
//
["prop_" + (() => 42)()]: 42,
};
:
var foo = { a: "alpha", 2: "two" };
console.log(foo.a); // alpha
console.log(foo[2]); // two
// console.log(foo.2); // SyntaxError: Unexpected number
// console.log(foo[a]); // ReferenceError: a is not defined
console.log(foo["a"]); // alpha
console.log(foo["2"]); // two
regexp - . regex:
var re = /ab+c/;
, ( " ) ( ' ) . , .. , . :
"foo" 'bar' "1234" "one line \n another line" "John's cat"
String : JavaScript String, , String. String.length :
console.log("John's cat".length);
// , .
// 10.
ES2015 . . Perl, Python . , , , .
// string
`In JavaScript '\n' is a line-feed.`;
//
`In JavaScript this is
not legal.`;
//
var name = "",
time = "";
` ${name}, ${time}?`;
// HTTP ,
POST`http://foo.org/bar?a=${a}&b=${b}
Content-Type: application/json
X-Credentials: ${credentials}
{ "foo": ${foo},
"bar": ${bar}}`(myOnReadyStateChangeHandler);
, String. String, String.
.
"one line \n another line";
, .
\b |
(Backspace) |
\f |
(Form feed) |
\n |
(New line) |
\r |
(Carriage return) |
\t |
(Tab) |
\v |
(Vertical tab) |
\' |
|
\" |
|
\\ |
(Backslash) |
\XXX |
Latin-1, XXX 0 377. , \251 ( ). |
\xXX |
Latin-1, XX 00 FF. , \xA9 ( ). |
\uXXXX |
Unicode, XXXX. , \u00A9 ( ). |
\u{XXXXX} |
UTF-32BE. , \u{2F804} , \uD87E\uDC04. |
, , . (deprecated) .
, . . :
var quote = "He read \"The Cremation of Sam McGee\" by R.W. Service.";
console.log(quote); // He read "The Cremation of Sam McGee" by R.W. Service.
, . :
var home = "c:\\temp"; // c:\temp
. . :
var str =
"this string \
is broken \
across multiple\
lines.";
console.log(str); // this string is broken across multiplelines.
JavaScript "heredoc" ( ), , :
var poem =
"Roses are red,\n\
Violets are blue.\n\
I'm schizophrenic,\n\
And so am I.";
. JavaScript, :
.
This page was last modified on 14 . 2025 . by MDN contributors.
Your blueprint for a better internet.
Portions of this content are 19982026 by individual mozilla.org contributors. Content available under a Creative Commons license.
| Web Proxy Viewer | New URL | Original Page |