const person = {
name: "John",
greet: function() {
const getMessage = () => `Hello, ${this.name}`;
return getMessage();
}
};
console.log(person.greet());Ответ:
Please open Telegram to view this post
VIEW IN TELEGRAM
const arr = new Array(1000000).fill(0).map((_, i) => i);
const results = [];
function method1() {
return arr.filter(x => x % 2 === 0).map(x => x * 2).slice(0, 3);
}
function method2() {
const result = [];
for (let i = 0; i < arr.length && result.length < 3; i++) {
if (arr[i] % 2 === 0) {
result.push(arr[i] * 2);
}
}
return result;
}
console.log(method1().join(','));
console.log(method2().join(','));
Ответ:
Please open Telegram to view this post
VIEW IN TELEGRAM
function* infiniteGenerator() {
let i = 0;
while (true) {
yield i++;
}
}
const weakMap = new WeakMap();
const gen = infiniteGenerator();
weakMap.set(gen, gen.next().value);
const result = weakMap.get(gen) + gen.next().value;
console.log(result);Ответ:
Please open Telegram to view this post
VIEW IN TELEGRAM
const words = ['a', 'b', 'c'];
const result = words.concat(1, 2, 3);
console.log(result);
Ответ:
Please open Telegram to view this post
VIEW IN TELEGRAM
function foo() {
return typeof arguments;
};
console.log(foo(1, 2, 3));
Ответ:
Please open Telegram to view this post
VIEW IN TELEGRAM
const a = { value: 1 };
const b = Object.create(a);
b.value = 2;
console.log(b.value);
console.log(a.value);Ответ:
JavaScript test | #JavaScript
Please open Telegram to view this post
VIEW IN TELEGRAM
const obj = { a: 1, b: { c: 2 } };
const frozen = Object.freeze(obj);
frozen.a = 99;
frozen.b.c = 88;
frozen.d = 77;
const sealed = Object.seal({ x: 10, y: 20 });
sealed.x = 30;
sealed.z = 40;
delete sealed.y;
console.log(obj.a, obj.b.c, obj.d);
console.log(sealed.x, sealed.y, sealed.z);Ответ:
JavaScript test | #JavaScript
Please open Telegram to view this post
VIEW IN TELEGRAM
class StateMachine {
constructor() {
this.state = 'idle';
this.transitions = {
idle: { start: 'running' },
running: { pause: 'paused', stop: 'idle' },
paused: { resume: 'running', stop: 'idle' }
};
}
transition(action) {
const validTransitions = this.transitions[this.state];
if (validTransitions && validTransitions[action]) {
this.state = validTransitions[action];
return true;
}
return false;
}
}
const machine = new StateMachine();
console.log(machine.transition('pause'));
console.log(machine.state);
console.log(machine.transition('start'));
console.log(machine.state);Ответ:
JavaScript test | #JavaScript
Please open Telegram to view this post
VIEW IN TELEGRAM
Россияне массово переходят на новый способ заработка – арбитраж криптовалют
Арбитраж – это единственная сфера, где можно зарабатывать от 5.000р в день. Причем потолка дохода вообще нет – те кто еще вчера не знал, что такое арбитраж, сегодня выходят на 200, 300 и даже 500 тысяч в месяц.
Чтобы войти в эту нишу, пока она не перегрелась, пользуйтесь инструкциями с канала Арбитраж Криптовалют.
Он идеально подходит людям, которые ничего не знают про заработок в интернете, но при этом хотят выйти на доход в $1000-2000.
Без вложений. Без серых схем и прочего барахла.
Успейте присоединиться, начать никогда не поздно: 👉 @arbcrypto
Арбитраж – это единственная сфера, где можно зарабатывать от 5.000р в день. Причем потолка дохода вообще нет – те кто еще вчера не знал, что такое арбитраж, сегодня выходят на 200, 300 и даже 500 тысяч в месяц.
Чтобы войти в эту нишу, пока она не перегрелась, пользуйтесь инструкциями с канала Арбитраж Криптовалют.
Он идеально подходит людям, которые ничего не знают про заработок в интернете, но при этом хотят выйти на доход в $1000-2000.
Без вложений. Без серых схем и прочего барахла.
Успейте присоединиться, начать никогда не поздно: 👉 @arbcrypto
const userInput = "<script>alert('xss')</script>";
const sanitized = userInput.replace(/<script[^>]*>.*?<\/script>/gi, '');
const users = new Map();
users.set('admin', { password: 'secret123', role: 'admin' });
users.set('guest', { password: 'guest', role: 'user' });
function authenticate(username, password) {
const user = users.get(username);
return user && user.password === password ? user.role : null;
}
const role1 = authenticate('admin', 'secret123');
const role2 = authenticate('guest', 'wrong');
const role3 = authenticate('hacker', 'secret123');
console.log(sanitized);
console.log(role1, role2, role3);Ответ:
JavaScript test | #JavaScript
Please open Telegram to view this post
VIEW IN TELEGRAM
var str="abcde";
for (var i=0;i<str.length;i++){
console.log(str.charAt(i),str.charCodeAt(i));
}
Ответ:
a 97
b 98
c 99
d 100
e 101
JavaScript test | #JavaScript
Please open Telegram to view this post
VIEW IN TELEGRAM
let a = 1;
setTimeout(() => {
a = 2;
}, 0);
console.log(a);
Ответ:
Please open Telegram to view this post
VIEW IN TELEGRAM
const obj = {
name: 'Sarah',
getName() { return this.name; },
getNameArrow: () => this.name
};
const { getName, getNameArrow } = obj;
const boundGetName = obj.getName.bind(obj);
console.log(getName());
console.log(getNameArrow());
console.log(boundGetName());
console.log(obj.getName());
console.log(obj.getNameArrow());Ответ:
Please open Telegram to view this post
VIEW IN TELEGRAM
console.log(MyClass);
class MyClass {
constructor() {
this.value = 42;
}
}
Ответ:
Please open Telegram to view this post
VIEW IN TELEGRAM
function foo() {
return typeof arguments;
};
console.log(foo(1, 2, 3));Ответ:
Please open Telegram to view this post
VIEW IN TELEGRAM
function processData() {
try {
console.log('start');
throw new Error('oops');
console.log('after throw');
} catch (e) {
console.log('catch');
return 'caught';
} finally {
console.log('finally');
}
console.log('end');
}
const result = processData();
console.log(result);Ответ:
Please open Telegram to view this post
VIEW IN TELEGRAM
const a = document.createElement("a");
a.id = "test1";
a.href = "test2";
document.body.appendChild(a);
console.log(window.test1);Ответ:
JavaScript test | #JavaScript
Please open Telegram to view this post
VIEW IN TELEGRAM
function Foo() {
this.bar = 1;
}
Foo.prototype.bar = 2;
const foo = new Foo();
console.log(foo.bar);Ответ:
JavaScript test | #JavaScript
Please open Telegram to view this post
VIEW IN TELEGRAM
const array = [1, 2, 3, 4, 5];
const result = array.filter(n => n % 2).map(n => n * 2);
console.log(result);
Ответ:
JavaScript test | #JavaScript
Please open Telegram to view this post
VIEW IN TELEGRAM
class EventManager {
constructor() {
this.listeners = new Map();
}
addListener(event, callback) {
if (!this.listeners.has(event)) {
this.listeners.set(event, new Set());
}
this.listeners.get(event).add(callback);
}
removeListener(event, callback) {
this.listeners.get(event)?.delete(callback);
}
}
const manager = new EventManager();
const handler = () => console.log('handled');
manager.addListener('click', handler);
manager.removeListener('click', () => console.log('handled'));
console.log(manager.listeners.get('click').size);Ответ:
JavaScript test | #JavaScript
Please open Telegram to view this post
VIEW IN TELEGRAM
const data = { a: 1, b: 2, c: 3 };
const { a, ...rest } = data;
const newObj = { ...rest, a, d: 4 };
const arr = [1, 2, 3, 4, 5];
const [first, , third, ...remaining] = arr;
const result = [...remaining, third, first];
console.log(newObj);
console.log(result);Ответ:
JavaScript test | #JavaScript
Please open Telegram to view this post
VIEW IN TELEGRAM