Location via proxy:   [ UP ]  
[Report a bug]   [Manage cookies]                
0% found this document useful (0 votes)
9 views

Javascript Questions

Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as TXT, PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
9 views

Javascript Questions

Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as TXT, PDF, TXT or read online on Scribd
You are on page 1/ 8

1.what is output ?

function sum(a, b) {
return a + b;
}
console.log(sum(1, '2'));

2.what is output ?
let number = 0;
console.log(number++);
console.log(++number);
console.log(number);

3. what is output ?
var num = 8;
var num = 10;
console.log(num);

4. what is output ?
const obj = { a: 'one', b: 'two', a: 'three' };
console.log(obj);

5. what is output ?
function sayHi() {
return (() => 0)();
}
console.log(typeof sayHi());

6. what is output ?
let person = { name: 'Lydia' };
const members = [person];\
person = null;

console.log(members);

7. what is output ?
const person = {
name: 'Lydia',
age: 21,
};

for (const item in person) {


console.log(item);
}

8. what is output ?
console.log(3 + 4 + '5');

9. what is output ?
const num = parseInt('7*6', 10);
clg(num)

10. what is the output ?


function getInfo(member, year) {
member.name = 'Lydia';
year = '1998';
}

const person = { name: 'Sarah' };


const birthYear = '1997';
getInfo(person, birthYear);

console.log(person, birthYear);

11. what is output ?


console.log(Number(2) === Number(2));
console.log(Boolean(false) === Boolean(false));

12. what is output ?


const list = [1 + 2, 1 * 2, 1 / 2];
console.log(list);

13.what is output ?
function sayHi(name) {
return `Hi there, ${name}`;
}
console.log(sayHi());

14. what is output ?


const person = {
name: 'Lydia',
age: 21,
};

let city = person.city;


city = 'Amsterdam';

console.log(person);

15. what is output ?


function sum(num1, num2 = num1) {
console.log(num1 + num2);
}
sum(10);

18.what is output ?
console.log(`${(x => x)('I love')} to program`);

19. what is output ?


const name = 'Lydia Hallie';

console.log(!typeof name === 'object');


console.log(!typeof name === 'string');

20.what is output ?
const myFunc = ({ x, y, z }) => {
console.log(x, y, z);
};

myFunc(1, 2, 3);

22. let a = 3;
let b = new Number(3);
let c = 3;
console.log(a == b);
console.log(a === b);
console.log(b === c);

23. let greeting;


greetign = {};
console.log(greetig);

24 . function checkAge(data) {
if (data === { age: 18 }) {
console.log('You are an adult!');
} else if (data == { age: 18 }) {
console.log('You are still an adult.');
} else {
console.log(`Hmm.. You don't have an age I guess`);
}
}

checkAge({ age: 18 });

25. console.log(typeof typeof 1);

26. const numbers = [1, 2, 3];


numbers[10] = 11;
console.log(numbers);

27 .
let person = { name: 'Lydia' };
const members = [person];
person = null;

console.log(members);

28. const person = {


name: 'Lydia',
age: 21,
};

for (const item in person) {


console.log(item);
}

29. function getInfo(member, year) {


member.name = 'Lydia';
year = '1998';
}

const person = { name: 'Sarah' };


const birthYear = '1997';

getInfo(person, birthYear);
console.log(person, birthYear);

30. (() => {


let x = (y = 10);
})();

console.log(typeof x);
console.log(typeof y);

31. const name = 'Lydia';


age = 21;

console.log(delete name);
console.log(delete age);

33. function addToList(item, list) {


return list.push(item);
}

const result = addToList('apple', ['banana']);


console.log(result);

34. const box = { x: 10, y: 20 };

Object.freeze(box);

const shape = box;


shape.x = 100;

console.log(shape);

35. const { name: myName } = { name: 'Lydia' };

console.log(name);

36. function checkAge(age) {


if (age < 18) {
const message = "Sorry, you're too young.";
} else {
const message = "Yay! You're old enough!";
}

return message;
}

console.log(checkAge(21));

37. console.log('I want pizza'[0]);

38. let newList = [1, 2, 3].push(4);


console.log(newList.push(5));

39. const person = {


name: 'Lydia',
age: 21,
};

for (const [x, y] of Object.entries(person)) {


console.log(x, y);
}

40. function nums(a, b) {


if (a > b) console.log('a is bigger');
else console.log('b is bigger');
return;
a + b;
}

console.log(nums(4, 2));
console.log(nums(1, 2));

41. const name = 'Lydia';

console.log(name());

42. const one = false || {} || null;


const two = null || false || '';
const three = [] || 0 || true;

console.log(one, two, three);

43. function compareMembers(person1, person2 = person) {


if (person1 !== person2) {
console.log('Not the same!');
} else {
console.log('They are the same!');
}
}

const person = { name: 'Lydia' };

compareMembers(person);

44. const colorConfig = {


red: true,
blue: false,
green: true,
black: true,
yellow: false,
};

const colors = ['pink', 'red', 'blue'];

console.log(colorConfig.colors[1]);

45. let name = 'Lydia';

function getName() {
console.log(name);
let name = 'Sarah';
}

getName();

46. console.log(`${(x => x)('I love')} to program`);

47. const add = x => y => z => {


console.log(x, y, z);
return x + y + z;
};

add(4)(5)(6);

48. const myFunc = ({ x, y, z }) => {


console.log(x, y, z);
};

myFunc(1, 2, 3);

49. const person = { name: 'Lydia Hallie' };

Object.seal(person);

50 . const person = {
name: 'Lydia Hallie',
address: {
street: '100 Main St',
},
};

Object.freeze(person);

51.const add = x => x + x;


function myFunc(num = 2, value = add(num)) {
console.log(num, value);
}

myFunc();
myFunc(3);

52. let count = 0;


const nums = [0, 1, 2, 3];

nums.forEach(num => {
if (num) count += 1
})

console.log(count)

53. const user = {


email: "e@mail.com",
password: "12345"
}

const updateUser = ({ email, password }) => {


if (email) {
Object.assign(user, { email })
}

if (password) {
user.password = password
}

return user
}

const updatedUser = updateUser({ email: "new@email.com" })

console.log(updatedUser === user)

54. const user = {


email: "my@email.com",
updateEmail: email => {
this.email = email
}
}

user.updateEmail("new@email.com")
console.log(user.email)

55.
const bird = {
size: 'small',
};
const mouse = {
name: 'Mickey',
small: true,
};

console.log(bird)
console.log(mouse)

You might also like