The most important JavaScript concepts you must know!
- What is JavaScript?
Ans: JavaScript is a lightweight , interpreted Programming language with Object Oriented capabilities.
2. Data types in JavaScript?
Ans: 1. String
2. Number
3. Symbol
4. Boolean
5. Object
6. Null
7. Undefined
3. What is parseInt and parseFloat?
Ans: parseInt is a JavaScript built in method which converts the value into an integer number.
Ex: console.log(parseInt(3.25)) /output(3)
parseFloat is a JavaScript built in method which converts the value into floating point number.
Ex: console.log(parseFloat(“3.33333”)) /output(3.33333)
4. What is Array?
Ans: Array is a data structure that contains a group of elements. In JavaScript, Array is a special type of object. Here are some important Array Methods-
1. Array.length()
2. Array.push(item)
3. Array.pop()
4. Array.shift()
5. Array.unshift(item)
6. Array.splice()
7. Array.slice()
8. Array.concat()
9. Array.indexOf(item)
10. Array.includes(item)
11. Array.find()
12. Array.filter()
13. Array.map()
14. Array.sort()
15. Array.reverse()
5. What is Object?
Ans: Object can hold multiple values in terms of properties(key and value pair) and methods(functions). Here are some important Object methods-
1. Object.create()
2. Object.keys()
3. Object.values()
4. Object.entries()
5. Object.assign()
6. Object.freeze()
7. Object.seal()
8. Object.getPrototypeOf()
6. Differentiate between Argument and Parameter ?
Ans: When a function is called, the values that are passed during the call are arguments.
The Values which are defined at the time of the definition of the function are called parameters.
Ex: function add(a,b){
return a+b;
} // ((a,b) are the parameters);
add(20,30) // ((20,30) are the arguments);
7. What are the principles of oop ?
Ans:
1. Inheritence
2. Encapsulation
3. Polymorphism
4. Abstraction
8. What is Boolean ?
Ans: Boolean is a data type which returns true or false.
* false, 0, NaN, Null, Undefined are the false value.
* All the others value are true.
9. Differentiate between Let and Const ?
Ans: Let is a block level variable. It is not accessible outside of it’s block. Variable with let can be re-assignable.
Const variable can’t be re-assigned. It will through an error if we want to re-assign the value of Const.
10. Difference between “==” and “===” ?
Ans: “==” checks only the value is same or not. If it is same then returns true.
“===” check both the value and the data type. If both are same then returns true , else false.
11. What is Short-circuit logic ?
Ans: && checks both condition is true or not. If true then execute the program
|| checks at least one is true. It it is then execute the program.
12. What is ternary operator ?
Ans: If there need to check only two conditions to execute the program, then ternary operator can be used.
Ex: let age = 22;
let level = (age>18) ? ‘Adult’ : ‘Child’;
console.log(level) // output(Adult);
This is similar to-
if(age>18){
level = ‘Adult’
}else {
level = ‘Child’
}