function test1(){
return{
name: "Atahan Koc"
}
}
function test2(){
return
{
name: "Atahan Koc"
}
}
console.log(test1());
console.log(test2());
Answer
{ name: 'Atahan Koc' } undefined
The code defines two functions, test1 and test2.
In test1, an object with the name property set to "Atahan Koc" is returned. In test2, a line break after the return statement causes JavaScript's automatic semicolon insertion rule to add a semicolon. As a result, the return statement returns an empty value, leading to undefined being returned.
When test1() is called, it returns an object { name: 'Atahan Koc' }.
When test2() is called, it returns undefined.
The difference in return values arises due to the line break and automatic semicolon insertion in test2.
console.log(1<2<3);
console.log(3>2>1);
Answer
true false
First, 1 < 2 is evaluated, which returns true because 1 is less than 2. Then, true < 3 is evaluated. JavaScript automatically converts logical values to numerical values, with true being converted to 1. As a result, the expression is evaluated as 1 < 3, which is true. Therefore, the first console.log prints true. The second console.log expression evaluates the expression 3 > 2 > 1. It is also evaluated from left to right.
First, 3 > 2 is evaluated, which returns true because 3 is greater than 2. Then, true > 1 is evaluated. JavaScript automatically converts true to the numerical value 1. However, it's important to note that 1 > 1 is false because 1 is not greater than 1; it's equal to 1. Therefore, the expression is evaluated as true > 1, which is false. As a result, the second console.log prints false.
Answer
JavaScript, unlike some other languages, treats null and undefined as two distinct concepts.
In JavaScript, undefined means that a variable has been declared but has not been assigned a value yet.
On the other hand, null is an assignment value that can be assigned to a variable to represent the absence of a value. When we use the typeof operator on null, it returns "object" indicating that null is considered an empty object reference.
var bar = true;
console.log(bar + 0);
console.log(bar + "xyz");
console.log(bar + true);
console.log(bar + false);
Answer
output:
1
"truexyz"
2
1
var arrA = [0,1,2,3,4,5];
var arrB = arrA.slice();
arrB[0]=42;
console.log(arrA)
Answer
The output will be [0,1,2,3,4,5]
.
The slice
function copies all the elements of the array returning the new array. That's why
arrA
and arrB
reference two completely different arrays.
Answer
Void(0) is used to prevent the page from refreshing, and it passes the parameter "zero" during the execution.Answer
Following are the JavaScript Data types:
- Number
- String
- Boolean
- Object
- Undefined
Answer
- alert
- confirm
- prompt
Answer
Progressive rendering is an approach in web development that focuses on displaying content to users as quickly as possible, even before the entire web page has finished loading.
Answer
The debugger for the browser must be activated in order to debug the code. Built-in debuggers may be switched on and off, requiring the user to report faults. The remaining section of the code should stop execution before moving on to the next line while debugging.Answer
The "==" operator is used to compare values, while the "===" operator is used to compare both values and types.Answer
Date objects inherit properties from the Date prototype Math objects inherit properties from the Math prototype Array objects inherit properties from the Array prototype.Answer
A callback is a function that will be executed after another function gets executed. In javascript, functions are treated as first-class citizens, they can be used as an argument of another function, can be returned by another function, and can be used as a property of an object.(function() {
var objA = {
foo: 'foo',
bar: 'bar'
};
var objB = {
foo: 'foo',
bar: 'bar'
};
console.log(objA == objB);
console.log(objA === objB);
}());
a. false true b. false false c. true true d. true false
Answer
b. false false(function() {
var objA = {
foo: 'foo'
};
var objB = objA;
objB.foo = 'bar';
delete objA.foo;
console.log(objA.foo);
console.log(objB.foo);
}());
Answer
Inside the function, objA is defined as an object with a foo property set to "foo".objB is then assigned the reference of objA, so both objA and objB point to the same object.
The value of objB.foo is changed to "bar". Since both objA and objB reference the same object, this change affects both variables.
The foo property is deleted from objA.
The first console.log statement evaluates objA.foo. Since the foo property was deleted, its value is undefined.
The second console.log statement evaluates objB.foo. Since objB still refers to the modified object, the value of foo is "bar".
In summary, the first console.log outputs undefined because the foo property was deleted from objA, while the second console.log outputs "bar" because objB still refers to the modified object.
let arrayIntegers = [1, 2, 3, 4, 5];
let arrayIntegers1 = arrayIntegers.slice(0, 2);
let arrayIntegers2 = arrayIntegers.slice(2, 3);
let arrayIntegers3 = arrayIntegers.slice(4);
Answer
// returns [1,2] // returns [3] // returns [5]Answer
First-order function is a function that doesn’t accept another function as an argument and doesn’t return a function as its return value.const firstOrder = () => console.log("I am a first order function!");
Answer
Below are the list of benefits using modules in javascript ecosystemMaintainability Reusability Namespacing
console.log("🙂" === "🙂");
Answer
trueconsole.log(typeof typeof typeof true);
1: string 2: boolean 3: NaN 4: number
Answer
1: stringlet zero = new Number(0);
if (zero) {
console.log("If");
} else {
console.log("Else");
}
A: If B: Else C: NaN D: SyntaxError
Answer
A: Iflet count = 10;
(function innerFunc() {
if (count === 10) {
let count = 11;
console.log(count);
}
console.log(count);
})();
Answer
11, 10getMessage();
var getMessage = () => {
console.log("Good morning");
};
A: Good morning
B: getMessage is not a function
C: getMessage is not defined
D: Undefined
Answer
B : getMessage is not a functionconst resp = () => {
return (()=> 0 )();
}
console.log("typeof : "+ typeof resp())
Answer
typeof : numberAnswer
"NaN" stands for "Not a Number." It is used to indicate an invalid number result when performing a mathematical operation in JavaScript.Answer
"Prototype" is a feature in JavaScript used to share properties and methods among objects. When an object is created, its properties and methods can be accessed through the prototype chain.Answer
"Promise" is a construct used to manage asynchronous operations in JavaScript. It returns an object that represents the eventual completion or failure of an asynchronous operation and provides a way to handle the returned value. "Promise" is used with the "then()" and "catch()" methods to perform relevant actions when the operation is successful or when an error occurs.Answer
NaN. If you pass an array to the Math.max() function, the result will be NaN (Not a Number).Answer
3let a="hello";
let b =`hello`;
console.log(a === b);
console.log(a == b);
Answer
true truelet a =1;
let b =1;
let c =2;
console.log(a === b === -c);
Answer
a===b gives True. true === -c(number) gives false.const func = (function(a){
delete a;
return a;
} )(5)
console.log(func);
Answer
output: 5const person1 = {
name : "Atahan"
}
const person2 = {
name : "Gokce"
}
const person = Object.assign(person1, person2);
console.log(person);
console.log(person.name);
console.log(person1.name);
console.log(person2.name);
Answer
Having same key name so, the value is override and it will be "Gokce"function sayHi() {
console.log(name);
console.log(age);
var name = 'Lydia';
let age = 21;
}
sayHi();
Answer
UndefinedReferenceError
for (var i = 0; i < 3; i++) {
setTimeout(() => console.log(i), 1);
}
for (let i = 0; i < 3; i++) {
setTimeout(() => console.log(i), 1);
}
Answer
Output: 3 3 3 - 1 2 3+true;
!'Ata';
Answer
1 and Falselet c = { greeting: 'Hey!' };
let d;
d = c;
c.greeting = 'Hello';
console.log(d.greeting);
Answer
Hellolet a = 3;
let b = new Number(3);
let c = 3;
console.log(a == b);
console.log(a === b);
console.log(b === c);
Answer
TrueFalse False
let greeting;
greetign = {}; // Typo!
console.log(greetign);
Answer
{}function Person(firstName, lastName) {
this.firstName = firstName;
this.lastName = lastName;
}
const member = new Person('Lydia', 'Hallie');
Person.getFullName = function() {
return `${this.firstName} ${this.lastName}`;
};
console.log(member.getFullName());
Answer
The output will be "TypeError: member.getFullName is not a function". At the beginning of the code, the function Person is defined as a constructor function, and it does not have a property named getFullName. Then, an object named member is created as an instance of the Person constructor.Answer
False - All objects have prototypes, except for the base object.let number = 0;
console.log(number++);
console.log(++number);
console.log(number);
Answer
0 2 2const sum = eval('10*10+5');
Answer
105var num = 8;
var num = 10;
console.log(num);
Answer
10 - With the var keyword, you can declare multiple variables with the same name. The variable will then hold the latest value.!!null;
!!'';
!!1;
Answer
false - true - true[] - You should not use any of the JavaScript reserved keyword as variable name.
[] - JavaScript variable names should not start with a numeral (0-9).
[] - Both of the above.
[] - None of the above.
Answer
[X] - Both of the above.[] - global variable
[] - local variable
[] - Both of the above
[] - None of the above
Answer
[X] - global variable[] - global variable
[] - local variable
[] - Both of the above
[] - None of the above
Answer
[X] - local variableuniq([]) // []
uniq([1, 4, 2, 2, 3, 4, 8])
Answer
uniq([1, 4, 2, 2, 3, 4, 8]) // [1, 4, 2, 3, 8]Question 47: Which statement is the correct way to create a variable called rate and assign it the value 100?
[] - let rate = 100;
[] - let 100 = rate;
[] - 100 = let rate;
[] - rate = 100;
Answer
[] - let rate = 100;Question 48: Which statement creates a new object using the Person constructor? Which statement creates a new Person object called "student"?
- [ ] `var student = new Person();`
- [ ] `var student = construct Person;`
- [ ] `var student = Person();`
- [ ] `var student = construct Person();`
Answer
`var student = new Person();`- [ ] It reloads the document whenever the value changes.
- [ ] It returns a reference to a variable in its parent scope.
- [ ] It completes execution without returning.
- [ ] It copies a local variable to the global scope.
Answer
- [x] It returns a reference to a variable in its parent scope.console.log(typeof 42);
-
'float'
-
'value'
-
'number'
-
'integer'
-
JSON.fromString();
-
JSON.parse()
-
JSON.toObject()
-
JSON.stringify()
-
throw
-
exception
-
catch
-
error
let answer = true;
if (answer === false) {
return 0;
} else {
return 10;
}
- 10
- true
- false
- 0
-
attachNode()
-
getNode()
-
querySelector()
-
appendChild()
-
break
-
pass
-
skip
-
continue
-
array.slice()
-
array.shift()
-
array.push()
-
array.replace()