output questions
1.<!DOCTYPE html>
<html>
<body>
<button id="myButton">Click me</button>
<p id="output"></p>
<script>
document.getElementById("myButton").addEventListener("click", function() {
document.getElementById("output").textContent = "Button was clicked!";
});
</script>
</body>
</html>
2.
let x = { b: 1, c: 2 };
let y = Object.keys(x);
console.log(y.length);
3.
let x = "5";
let y = 2;
console.log(x + y);
console.log(x - y);
4.
let x = "hello";
let y = new String("hello");
console.log(x == y);
console.log(x === y);
5.
let x = 1;
let y = "1";
console.log(++x, ++y);
6.
let x = { a: 1, b: 2 };
let y = { b: 3 };
let z = { ...x, ...y };
console.log(z);
7.
let x = { a: 1 };
let y = Object.assign({}, x);
console.log(x === y);
8.
let x = 5;
let y = 6;
x += x > y ? x : y;
console.log(x);
9.
let x = [1, 2, 3];
let y = x.map((x, i) => x + i);
console.log(y);
10.
let x = ["apple", "banana", "cherry"];
let y = x.filter((i) => i.startsWith("b"));
console.log(y);
11.
let x = 10.5;
let y = parseInt(x);
console.log(y);
12.
let x = [1];
let y = x + 1;
console.log(y);
13.
let x = [1, 2, 3];
let y = x.slice();
console.log(y, x === y);
14.
const a = [1, 2, 3];
const b = [...a];
b.push(4);
console.log(a);
15.
let a = [1, 2, 3];
let b = [4, 5, 6];
console.log(a + b);
16.
let x = [1, 2, 3];
console.log(x.concat(4, 5));
17.
<!DOCTYPE html>
<html>
<body>
<ul id="myList">
<li>Item 1</li>
<li>Item 2</li>
</ul>
<script>
let newItem = document.createElement("li");
newItem.textContent = "Item 3";
document.getElementById("myList").appendChild(newItem);
</script>
</body>
</html>
18.
let c = { greeting: 'Hey!' };
let d;
d = c;
c.greeting = 'Hello';
console.log(d.greeting);
19.
let greeting;
greetign = {};
console.log(greetign);
20.
function sum(a, b) {
return a + b;
}
sum(1, '2');
21.
let number = 0;
console.log(number++);
console.log(++number);
console.log(number);
22.
function getAge() {
'use strict';
age = 21;
console.log(age);
}
getAge();
23.
const sum = eval('10*10+5');
24.
const obj = { a: 'one', b: 'two', a: 'three' };
console.log(obj);
25.
for (let i = 1; i < 5; i++) {
if (i === 3) continue;
console.log(i);
}
26.
<div onclick="console.log('div')">
<p onclick="console.log('p')">
Click here!
</p>
</div>
27.
const firstPromise = new Promise((res, rej) => {
setTimeout(res, 500, 'one');
});
const secondPromise = new Promise((res, rej) => {
setTimeout(res, 100, 'two');
});
Promise.race([firstPromise, secondPromise]).then(res => console.log(res));
28.
let person = { name: 'Lydia' };
const members = [person];
person = null;
console.log(members);
29.
const person = {
name: 'Lydia',
age: 21,
};
for (const item in person) {
console.log(item);
}
30.
const set = new Set([1, 1, 2, 3, 4]);
console.log(set);
No comments:
Post a Comment