| [ Web Proxy ] |
| Viewing: https://developer.mozilla.org/ru/docs/Web/JavaScript/Guide/Language_overview | [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 , . , . JavaScript , , .
. JavaScript 1995 , Netscape. Netscape 2 1996 . LiveScript, , Java Sun Microsystem . .
Microsoft JScript, IE3. Netscape Ecma International, , ECMAScript 1997. ECMAScript edition 3 1999, . , - . ECMAScript 5 ( 2009) ECMAScript 6 ( 2015).
, JavaScript (input) (output). , , . , JavaScript Adobe Acrobat, Photoshop, Yahoo!'s Widget engine, , node.js.
JavaScript - , , . Java C, JavaScript. JavaScript , ( ES6 Classes) . , , -, .
: . JavaScript , . JavaScript:
, Undefined Null, . , . , . , , . :
JavaScript "64- IEEE 754", . . JavaScript , , , C Java. :
0.1 + 0.2 == 0.30000000000000004;
32- ( ), .
, , , .. , , Math, :
Math.sin(3.5);
var circumference = Math.PI * (r + r);
, parseInt(). , :
parseInt("123", 10); // 123
parseInt("010", 10); // 10
, :
parseInt("010"); // 8
parseInt("0x10"); // 16
, parseInt() - 0, - - "0x".
, :
parseInt("11", 2); // 3
, parseFloat(), 10 parseInt().
+ :
+"42"; // 42
+"0x10"; // 16
NaN ( "Not a Number") , :
parseInt("hello", 10); // NaN
NaN "": NaN NaN:
NaN + 5; // NaN
NaN isNaN():
isNaN(NaN); // true
JavaScript Infinity () -Infinity:
1 / 0; // Infinity
-1 / 0; // -Infinity
Infinity, -Infinity NaN isFinite():
isFinite(1 / 0); // false
isFinite(-Infinity); // false
isFinite(NaN); // false
JavaScript - Unicode ( UTF-16). , , . , - , 16- , Unicode 1 2 .
, , .
( ), length:
"hello".length; // 5
"hello".charAt(0); // h
"hello, world".replace("hello", "goodbye"); // goodbye, world
"hello".toUpperCase(); // HELLO
JavaScript , null, , undefined, , , . , JavaScript . "undefined".
JavaScript () , true false ( ). :
false, 0, (""), NaN, null undefined false.true. , Boolean():
Boolean(""); // false
Boolean(234); // true
, JavaScript , , if. - , , , "" "".
: && ( ), || ( ), ! ( ).
let a;
let name = "Simon";
let , , :
// myLetVariable
for (let myLetVariable = 0; myLetVariable < 5; myLetVariable++) {
// myLetVariable
}
// myLetVariable
const , . , .
const Pi = 3.14; // Pi .
Pi = 1; // , .
var . , . , JavaScript. , var, , .
var a;
var name = "Simon";
, var:
// myVarVariable
for (var myVarVariable = 0; myVarVariable < 5; myVarVariable++) {
// myVarVariable
}
// myVarVariable
- , undefined.
JavaScript , , . , var (, if), . , ECMAScript Edition 6 let const, , .
JavaScript , +, -, *, / %, ( ). =, += -=. x = x y.
x += 5;
x = x + 5;
(++) (--). .
+ () :
"hello" + " world"; // "hello world"
. :
"3" + 4 + 5; // "345"
3 + 4 + "5"; // "75"
.
JavaScript : <, >, <= >=. , . . (==) (===) . == , :
123 == "123"; // true
1 == true; // true
, :
1 === true; // false
123 === "123"; // false
true === true; // true
!= !==.
JavaScript C. if else, :
var name = "kittens";
if (name == "puppies") {
name += "!";
} else if (name == "kittens") {
name += "!!";
} else {
name = "!" + name;
}
name == "kittens!!";
JavaScript : while, do-while for. While , do-while , , :
while (true) {
// !
}
var input;
do {
input = get_input();
} while (inputIsNotValid(input));
for C Java: :
for (var i = 0; i < 5; i++) {
// 5
}
JavaScript : for...of
for (let value of array) {
// value
}
for (let property in object) {
//
}
&& || " ", , . , , :
var name = o && o.getName();
:
var name = otherName || "default";
JavaScript "?" :
var allowed = age > 18 ? "yes" : "no";
switch :
switch (action) {
case "draw":
drawit();
break;
case "eat":
eatit();
break;
default:
donothing();
}
case break, case. , , , :
switch (a) {
case 1: // fallthrough
case 2:
eatit();
break;
default:
donothing();
}
default . switch, cases. ===:
switch (1 + 3) {
case 2 + 2:
yay();
break;
default:
neverhappens();
}
JavaScript - (-). :
JavaScript , JavaScript, . .
:
var obj = new Object();
:
var obj = {};
. . JSON, .
, :
var obj = {
name: "Carrot",
for: "Max",
details: {
color: "orange",
size: 12,
},
};
:
obj.details.color; // orange
obj["details"]["size"]; // 12
// Syntax error, 'for'
obj.for = "Simon";
//
obj["for"] = "Simon";
Inheritance and the prototype chain.
JavaScript . ( , []), length (). , + 1.
:
var a = new Array();
a[0] = "dog";
a[1] = "cat";
a[2] = "hen";
a.length; // 3
:
var a = ["dog", "cat", "hen"];
a.length; // 3
, array.length . :
var a = ["dog", "cat", "hen"];
a[100] = "fox";
a.length; // 101
.
, undefined:
typeof a[90]; // undefined
:
for (var i = 0; i < a.length; i++) {
// - a[i]
}
ES2015 for...of , .. :
for (const currentValue of a) {
// - currentValue
}
for...in. , - Array.prototype, . .
ECMAScript 5 forEach():
["dog", "cat", "hen"].forEach(function (currentValue, index, array) {
// - currentValue array[index]
});
push():
a.push(item);
a.toString() |
, . |
a.toLocaleString() |
. |
a.concat(item1[, item2[, ...[, itemN]]]) |
. |
a.join(sep) |
, sep |
a.pop() |
. |
a.push(item1, ..., itemN) |
. |
a.reverse() |
. |
a.shift() |
. |
a.slice(start[, end]) |
. |
a.sort([cmpfn]) |
. |
a.splice(start, delcount[, item1[, ...[, itemN]]]) |
. |
a.unshift(item1[, item2[, ...[, itemN]]]) |
. |
JavaScript. :
function add(x, y) {
var total = x + y;
return total;
}
, . JavaScript . , . return . return ( , ), JavaScript undefined.
, . , undefined:
add(); // NaN
// undefined undefined
, :
add(2, 3, 4); // 5
// , "4"
, "" arguments, , . , :
function add() {
var sum = 0;
for (var i = 0, j = arguments.length; i < j; i++) {
sum += arguments[i];
}
return sum;
}
add(2, 3, 4, 5); // 14
:
function avg() {
var sum = 0;
for (var i = 0, j = arguments.length; i < j; i++) {
sum += arguments[i];
}
return sum / arguments.length;
}
avg(2, 3, 4, 5); // 3.5
, . . , . : ...variable , . for for...of , .
function avg(...args) {
var sum = 0;
for (let value of args) {
sum += value;
}
return sum / args.length;
}
avg(2, 3, 4, 5); // 3.5
JavaScript :
var avg = function () {
var sum = 0;
for (var i = 0, j = arguments.length; i < j; i++) {
sum += arguments[i];
}
return sum / arguments.length;
};
function avg(). . , "" :
var a = 1;
var b = 2;
(function () {
var b = 3;
a += b;
})();
a; // 4
b; // 2
JavaScript . () ( , DOM).
function countChars(elm) {
if (elm.nodeType == 3) {
// TEXT_NODE
return elm.nodeValue.length;
}
var count = 0;
for (var i = 0, child; (child = elm.childNodes[i]); i++) {
count += countChars(child);
}
return count;
}
: , ? JavaScript IIFEs (Immediately Invoked Function Expressions). :
var charsInBody = (function counter(elm) {
if (elm.nodeType == 3) {
// TEXT_NODE
return elm.nodeValue.length;
}
var count = 0;
for (var i = 0, child; (child = elm.childNodes[i]); i++) {
count += counter(child);
}
return count;
})(document.body);
. .
- () , . JavaScript - , , , , C++ Java. ( , , .) JavaScript . , . : " " ", ". :
function makePerson(first, last) {
return {
first: first,
last: last,
};
}
function personFullName(person) {
return person.first + " " + person.last;
}
function personFullNameReversed(person) {
return person.last + ", " + person.first;
}
s = makePerson("Simon", "Willison");
personFullName(s); // Simon Willison
personFullNameReversed(s); // Willison, Simon
, . , . , . , :
function makePerson(first, last) {
return {
first: first,
last: last,
fullName: function () {
return this.first + " " + this.last;
},
fullNameReversed: function () {
return this.last + ", " + this.first;
},
};
}
s = makePerson("Simon", "Willison");
s.fullName(); // Simon Willison
s.fullNameReversed(); // Willison, Simon
- : this. this , . . , this . this . . :
s = makePerson("Simon", "Willison");
var fullName = s.fullName;
fullName(); // undefined undefined
fullName(), this . first last, undefined.
this, makePerson:
function Person(first, last) {
this.first = first;
this.last = last;
this.fullName = function () {
return this.first + " " + this.last;
};
this.fullNameReversed = function () {
return this.last + ", " + this.first;
};
}
var s = new Person("Simon", "Willison");
: new. this. , , this . , new . , - .
, fullName().
, , . :
function personFullName() {
return this.first + " " + this.last;
}
function personFullNameReversed() {
return this.last + ", " + this.first;
}
function Person(first, last) {
this.first = first;
this.last = last;
this.fullName = personFullName;
this.fullNameReversed = personFullNameReversed;
}
: - , - . ? :
function Person(first, last) {
this.first = first;
this.last = last;
}
Person.prototype.fullName = function fullName() {
return this.first + " " + this.last;
};
Person.prototype.fullNameReversed = function fullNameReversed() {
return this.last + ", " + this.first;
};
Person.prototype , Person. . , Person, JavaScript , Person.prototype. , Person.prototype, this .
. JavaScript , , :
s = new Person("Simon", "Willison");
s.firstNameCaps();
// TypeError on line 1: s.firstNameCaps is not a function
Person.prototype.firstNameCaps = function () {
return this.first.toUpperCase();
};
s.firstNameCaps(); // "SIMON"
, JavaScript. reversed String, :
var s = "Simon";
s.reversed(); // TypeError on line 1: s.reversed is not a function
String.prototype.reversed = function reversed() {
var r = "";
for (var i = this.length - 1; i >= 0; i--) {
r += this[i];
}
return r;
};
s.reversed(); // "nomiS"
!
"This can now be reversed".reversed();
// desrever eb won nac sihT
, prototype . Object.prototype, toString() , , . Person:
var s = new Person("Simon", "Willison");
s.toString(); // [object Object]
Person.prototype.toString = function () {
return "<Person: " + this.fullName() + ">";
};
s.toString(); // "<Person: Simon Willison>"
, avg.apply() null? : , apply() , this. new:
function trivialNew(constructor, ...args) {
var o = {}; //
constructor.apply(o, args);
return o;
}
new, ( ). apply() , . , ...args ( ) , .
var bill = trivialNew(Person, "William", "Orange");
:
var bill = new Person("William", "Orange");
JavaScript apply() call(), this, , .
function lastNameCaps() {
return this.last.toUpperCase();
}
var s = new Person("Simon", "Willison");
lastNameCaps.call(s);
// :
s.lastNameCaps = lastNameCaps;
s.lastNameCaps(); // WILLISON
. , makePerson(). , , -:
function parentFunc() {
var a = 1;
function nestedFunc() {
var b = 4; // parentFunc can't use this
return a + b;
}
return nestedFunc(); // 5
}
, . , , . , .
. , . , . -, ( ), .
JavaScript. .
function makeAdder(a) {
return function (b) {
return a + b;
};
}
var x = makeAdder(5);
var y = makeAdder(20);
x(6); // ?
y(7); // ?
makeAdder , , .
, , . . , . . "" makeAdder, ( , - 5, - 20). :
x(6); // 11
y(7); // 27
: JavaScript , 'scope', , . , . 'Scope' , , : 'scope' , , 'scope' . .
makeAdder 'scope' : a, , . makeAdder . ' ' scope, . scope , .
scope , JavaScript.
This page was last modified on 10 . 2026 . 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 |