// Вызываем функцию, результат кладем в переменную
const result = myFunction();
// Обычное объявление
function muFuncion() { }
// Выражение с анонимной функцией
const myFunction = function() { }
// Выражение с именованной функцией
const myFunc = function myFunction() { }
// Объявление стрелочной функции
const myFunction = () => { }
someFunction(function() {}) // анонимка
someFunction(() => {}) // стрелочная
nvm on
nvm list
– посмотреть какие версии у вас установленыnvm current
– посмотреть текущую (покажет то же, что node -v
)props.medications
.filter(f => f.Purposes.findIndex(i => props.purpose === i.Purpose) > -1)
// Если ни одного нет, findIndex вернет -1,
// условие не выполнится и элемент отфильтруется.
https://programest.github.io/lang.json
https://programest.github.io/AdilPortfolio/lang.json
/lang.json
– слеш вначале означает, что путь к файлу на сервере будет определятся от корня, то есть грубо говоря от названия сайта, от домена. В данном случае от https://programest.github.io
function makeItem(title) {
return `<a class="dropdown-item"><i class="icon icon-line-circle"></i><span>${title}</span></a>`;
}
fetch('../russia.json')
.then(response => response.json())
.then(json => {
const itemsHtmlString = json.map(item => makeItem(item.city)).join()
$('.search__city .dropdown-menu').html(itemsHtmlString);
});
(function () {
const themeCheckBox = document.querySelector('#theme-toggle')
const themeLabel = document.querySelector('.theme-toggle')
themeLabel.addEventListener('click', () => {
- localStorage.setItem('themeCheckBox', themeCheckBox.checked)
+ localStorage.setItem('themeCheckBox', themeCheckBox.checked ? '1' : '')
})
- themeCheckBox.checked = localStorage.getItem('themeCheckBox')
+ themeCheckBox.checked = !!localStorage.getItem('themeCheckBox')
})()
themeCheckBox.checked = localStorage.getItem('themeCheckBox')==='true'
if ( currentUrl.replace(/^\/|\/$/g, '') === [rootUrl.replace(/^\/|\/$/g, ''), relativeUrl.replace(/^\/|\/$/g, '')].join('/') ){
}
window.location.href
может содержать query string и hash string.new URL(window.location.href)
) и уже из этого объекта собирать URL domain + pathname.{
type: m.subType === 'warning' ? 'warn' : m.subType
}
{
type: m.subType,
}
var xhr = new XMLHttpRequest()
var smileResourc = '';
xhr.open(...)
xhr.send()
xhr.onreadystatechange = ...
// Строки выше отработаны и сразу же начинается выполнение условий !!!
if (typeof smileResourc[smileID] !== "undefined") {
return smileResourc[smileID];
} else {
var error = 'ID was not found, check if the ID was entered correctly';
console.log(error);
}
function smileTXT(smileID, callback){
// ...
xhr.onreadystatechange = function() {
if (xhr.readyState != 4) {
return
}
if (xhr.status === 200) {
smileResourc = JSON.parse(xhr.responseText);
callback(smileResourc);
} else {
console.log('err', xhr.responseText)
}
}
}
smileTXT('smileID', function(smileResourc){
console.log(smileResourc); // <- Вот он
if (typeof smileResourc[smileID] !== "undefined") {
// Что-то делаем с smileResourc[smileID];
} else {
var error = 'ID was not found, check if the ID was entered correctly';
console.log(error);
}
});