// Так писать не надо
var x = undefined;
foo(undefined, someValue):
// Так можно
var x = null;
foo(null, someValue);
if (someValue === undefined) {
doSomething()
}
Почему undefined является идентификатором а null литералом чем они отличаются ?
console.log(typeof undefined === 'undefined'); // true
var undefined = 'new value';
console.log(typeof undefined === 'undefined'); // false
ajcom.register('login', async (hCtx, email, pass) => {
const foundUser = await User.findOne({ where: { email } });
if (foundUser && foundUser.password === pass) {
console.log("Авторизация прошла успешно!");
isLoginIn = true;
} else {
console.log("Неверные данные, проверьте ваш email и пароль!");
}
return { authorized: isLoginIn };
});
var p = +$('input').val();
if (p === 1) {
// do something
} else if (p === 2) {
// do something else
}
switch(p) {
case 1:
// do something
break;
case 2:
// do something else
break;
}
const calculateAndDisplayRoute = callback => new Promise((resolve, reject) => {
var waypts = [];
return this.directionsService.route({
origin: "Аэропорт, Республика Башкортостан, Россия",
destination: $('#address_to').val(),
waypoints: waypts,
optimizeWaypoints: true,
travelMode: 'DRIVING'
}, (response, status) => {
if (status === 'OK') {
resolve(callback(response, status));
}
reject(status);
});
});
async function run() {
try {
await calculateAndDisplayRoute((response, status) => {
console.log(status);
result = status;
this.directionsDisplay.setDirections(response);
return true;
});
console.log(result);
} catch (e) {
console.log(e);
}
}
this.tail.next = newNode;
this.tail = newNode;
{
next: null,
value: 'xxx',
}
list.append('yyy');
{
next: {
next: null,
value: 'yyy',
},
value: 'xxx',
}
{
next: null,
value: 'yyy',
}
var data = {
fruits : [
{
src: 'http://.png',
data : 'Apple'
},
{
src : 'https://.png',
data : 'Banana'
}
],
vegetables : [
{
src: 'http://.png',
data : 'Carrot'
},
{
src : 'https://.png',
data : 'Potato'
}
]
};
var groups = Object.keys(data);
console.log(groups); // ['fruits', 'vegetables']
function Modal(options) {
this.el = (options && options.el) || document.body;
// init some options (text, width, onClose, onConfirm, etc)
this.init();
}
Modal.prototype.init() {
// build and append modal
}
Modal.prototype.show() {
// show modal and overlay
}
Modal.prototype.close() {
// close modal and overlay
}
var modal = new Modal(options);
var btn = document.querySelector('.btn');
btn.addEventListener('click', function() {
modal.show();
});
<script src="assets/js/main.js" type="module"></script>
function isIncludes(string, substring) {
return string.toLowerCase().indexOf(substring.toLowerCase()) !== -1;
}
if (isIncludes(value1, word1) && isIncludes(value2, word2)) {
console.log(word1, ' and ', word2);
}
function Entity(name) {
this.name = name;
}
Entity.prototype.write = function() {
console.log(this.name);
}
var calina = new Entity('calina');
calina.write();
{
message: "Новый объект!"
}