Skip to content

Instantly share code, notes, and snippets.

var person = {
firstName: 'John',
lastName: 'Snow'
};
var newPerson = person;
newPerson.lastName = 'Summer';
// person.lastName теперь 'Summer'
// function имя(список параметров) { тело }
function sum(a, b) {
var result = a + b;
return result;
}
// использование:
sum(1, 2) // 3
function ask(question, yes, no) {
if (confirm(question)) {
yes();
} else {
no();
}
}
function showOk() {
alert( "Вы согласились." );
function ask(question, yes, no) {
if (confirm(question)) yes()
else no();
}
ask(
"Вы согласны?",
function() { alert("Вы согласились."); },
function() { alert("Вы отменили выполнение."); }
);
var foo = function () {
var a = 3;
var b = 5;
var bar = function () {
var b = 7;
var c = 11; // a === 3, b === 7, c === 11
a += b + c; // a === 21, b === 7, c === 11
};
// a === 3, b === 5, c === undefined
bar();
var article1 = {
id: 1,
createdAt: new Date('2012-04-04T24:00:00')
};
var article2 = {
id: 1,
createdAt: new Date('2014-04-04T24:00:00')
}
.selector {
/* Positioning */
position: absolute;
z-index: 10;
top: 0;
right: 0;
/* Display & Box Model */
display: inline-block;
overflow: hidden;
function sayHi(name) {
var phrase = "Привет, " + name;
alert( phrase );
}
sayHi('Вася'); // Привет, Вася
alert(phrase) // undefined
var userName = "Вася";
function sayHi() {
alert( userName ); // "Вася"
}
var phrase = 'Привет';
function sayHi(name) {
alert(phrase + ', ' + name);
}
sayHi('Вася'); // Привет, Вася (*)
phrase = 'Пока';