JavaScript
document.getElementsByTagName('header')[0]
jQuery
$('header')
Chromium + V8
const year = 1999;
const year = 1999;
year = 2000; // TypeError: Assignment to constant variable.
let year;
year = 1999;
const year = 1999; // OK
const $year = 1999; // OK
const _year = 1999; // OK
const year1999 = 1999; // OK
const 1year = 1999; // Not OK!
* В качестве первого символа имени переменной можно использовать
буквы, символ доллара ($) и подчёркивание (_). Последующие символы
могут содержать всё вышеперечисленное, а также цифры.
const duration = 136;
const duration = 136;
console.log(duration); // 136
const duration = 136;
const hours = duration / 60; // 2.2666666666666666
const duration = 136;
const hours = Math.trunc(duration / 60); // 2
const duration = 136;
const hours = Math.trunc(duration / 60); // 2
const minutes = duration - (hours * 60); // 16
const duration = 136;
const hours = Math.trunc(duration / 60); // 2
const minutes = duration % 60; // 16
const duration = 136;
const hours = Math.trunc(duration / 60); // 2
const minutes = duration % 60; // 16
const minutesInHour = 60;
const duration = 136;
const hours = Math.trunc(duration / minutesInHour); // 2
const minutes = duration % minutesInHour; // 16
const minutesInHour = 60;
const duration = 25;
const hours = Math.trunc(duration / minutesInHour); // 0
const minutes = duration % minutesInHour; // 25
if (hours > 0) {
console.log('Hours:', hours);
console.log('Minutes:', minutes);
}
const minutesInHour = 60;
const duration = 25;
const hours = Math.trunc(duration / minutesInHour); // 0
const minutes = duration % minutesInHour; // 25
if (hours > 0) {
console.log('Hours:', hours);
console.log('Minutes:', minutes);
} else {
console.log('Minutes:', minutes);
}
const minutesInHour = 60;
const duration = 60;
const hours = Math.trunc(duration / minutesInHour); // 1
const minutes = duration % minutesInHour; // 0
if (hours > 0 && minutes > 0) {
console.log('Hours:', hours);
console.log('Minutes:', minutes);
} else if (hours > 0) {
console.log('Hours:', hours);
} else {
console.log('Minutes:', minutes);
}
const minutesInHour = 60;
const duration = 60;
const hours = Math.trunc(duration / minutesInHour); // 1
const minutes = duration % minutesInHour; // 0
const isHoursPositive = hours > 0; // true
const isHoursEqZero = hours === 0; // false
const isHoursAndMinutesPositive = hours > 0 && minutes > 0;
// true
const minutesInHour = 60;
const duration = 60;
const hours = Math.trunc(duration / minutesInHour); // 1
const minutes = duration % minutesInHour; // 0
const isHoursPositive = hours > 0;
const isHoursAndMinutesPositive = hours > 0 && minutes > 0;
if (isHoursAndMinutesPositive) {
console.log('Hours:', hours);
console.log('Minutes:', minutes);
} else if (isHoursPositive) {
console.log('Hours:', hours);
} else {
console.log('Minutes:', minutes);
}
const movie = 'The Matrix';
const movie = "The Matrix";
const movie = 'Операция «Ы»';
const movie = 'La vita è bella';
const movie = 'ハウルの動く城';
const movie = 'The Matrix';
const description = 'It\'s action movie';
const movie = 'The Matrix';
const description = 'It\'s action movie';
console.log(description.length); // 17
const movie = 'The Matrix';
const description = 'It\'s action movie';
console.log(movie + '. ' + description);
// 'The Matrix. It's action movie'
const movie = 'The Matrix';
movie[0]; // 'T'
const movie = 'The Matrix';
movie[0] = 'D';
console.log(movie); // 'The Matrix'
const movie = 'The Matrix';
for (let i = 0;;) {}
const movie = 'The Matrix';
for (let i = 0; i < movie.length;) {}
const movie = 'The Matrix';
for (let i = 0; i < movie.length; i++) {
const char = movie[i]; // 'T'
}
const movie = 'The Matrix';
for (let i = 0; i < movie.length; i++) {
const char = movie[i]; // 'h'
}
const movie = 'The Matrix';
for (let i = 0; i < movie.length; i++) {
const char = movie[i]; // 'e'
}
const movie = 'The Matrix';
for (let i = 0; i < movie.length; i++) {
const char = movie[i]; // 'x'
}
console.log(i); // ReferenceError: char is not defined
console.log(char); // ReferenceError: char is not defined
const genres = ['action', 'fantasy', 'sci-fi'];
const genres = ['action', 'fantasy', 'sci-fi'];
console.log(genres.length); // 3
const genres = ['action', 'fantasy', 'sci-fi'];
genres[0]; // 'action'
const genres = ['action', 'fantasy', 'sci-fi'];
genres[0] = 'comedy';
console.log(genres); // ['comedy', 'fantasy', 'sci-fi']
const genres = ['action', 'fantasy', 'sci-fi'];
genres.push('comedy');
console.log(genres);
// ['action', 'fantasy', 'sci-fi', 'comedy']
const genres = ['action', 'fantasy', 'sci-fi'];
for (let i = 0; i < genres.length; i++) {
const genre = genres[i]; // 'action'
}
const genres = ['action', 'fantasy', 'sci-fi'];
for (let i = 0; i < genres.length; i++) {
const genre = genres[i]; // 'fantasy'
}
const genres = ['action', 'fantasy', 'sci-fi'];
for (let i = 0; i < genres.length; i++) {
const genre = genres[i]; // 'sci-fi'
}
const genres = ['action', 'fantasy', 'sci-fi'];
genres[5]; // undefined
let year;
year; // undefined
year = 1999;
year; // 1999
const movie = {};
const movie = {
name: 'The Matrix'
};
const movie = {
name: 'The Matrix',
year: 1999,
genres: ['action', 'fantasy', 'sci-fi']
};
const movie = {
name: 'The Matrix',
year: 1999,
genres: ['action', 'fantasy', 'sci-fi']
};
console.log(movie.name); // 'The Matrix'
const movie = {
name: 'The Matrix',
year: 1999,
genres: ['action', 'fantasy', 'sci-fi']
};
const key = 'year';
console.log(movie[key]); // 1999
console.log(movie['na' + 'me']); // 'The Matrix'
const movie = {
name: 'The Matrix',
year: 1999,
genres: ['action', 'fantasy', 'sci-fi']
};
movie.name = 'Gatsby';
console.log(movie);
// { name: 'Gatsby',
// year: 1999,
// genres: [ 'action', 'fantasy', 'sci-fi' ] }
const movie = {
name: 'The Matrix',
year: 1999,
genres: ['action', 'fantasy', 'sci-fi']
};
movie.name = 'Gatsby';
movie.genres.push('comedy');
movie.duration = 136;
const movie = {
name: 'The Matrix',
year: 1999,
genres: ['action', 'fantasy', 'sci-fi']
};
delete movie.genres;
console.log(movie); // { name: 'The Matrix', year: 1999 }
const movie = {
name: 'The Matrix',
year: 1999,
genres: ['action', 'fantasy', 'sci-fi']
};
const keys = Object.keys(movie);
console.log(keys); // ['name', 'year', 'genres']
const movie = {
name: 'The Matrix',
year: 1999
};
function createMovie(name, year) {
return {
name: name,
year: year
};
}
function createMovie(name, year) {
return {
name: name,
year: year
};
}
function createMovie(name, year) {
return {
name,
year
};
}
function createMovie(name, year) {
return {
name,
year
};
}
console.log(createMovie('The Matrix', 1999));
// { name: 'The Matrix', year: 1999 }
function createMovie(name, year) {
return {
name,
year
};
}
console.log(
createMovie('The Matrix', 1999),
createMovie('The Green Mile', 1999),
createMovie('Bad Boys', 1995)
)
git clone https://github.com/urfu-...
demo-task-1
npm install
npm run lint
npm run test
git push