11. What are the different data types in JavaScript?
Primitive data types:
Boolean
Null
Undefined
Number
BigInt
String
Symbol
Non Primitive data type:
Object
12. What is the difference between “==” and “===” ?
Abstract Equality Comparison:
”==” only compares values
Strict Equality Comparison:
“===” compare values and data types both.
13. What is the use of type of operator?
'Typeof' operator is used to get the data type of the given variable in the string.
14. what is meant by Dynamic typing in JavaScript?
Whenever a variable is defined in angular it is not directly associated to any particular data type.
It changes its data types accordingly to the type of data assigned or de-assignee to it.
So JavaScript is a loosely typed or a dynamic language.
15. What is undefined in JavaScript?
Undefined is something that is not defined having no memory space assigned to it.
If a variable has not been assigned a value has the value undefined.
16. What is an Object in JavaScript?
An object is a collection of properties.
An object is a value in memory which is possibly referenced by an identifier.
In JavaScript, everything is an object, and all are derived from the object only.
17. What is strict mode in JavaScript?
Syntax: 'use strict';
It was introduced in ECMAScript 5.
Benefits of using strict mode:
It eliminates some JavaScript silent errors by changing them to throw errors.
It fixes mistakes that make it difficult for the JavaScript engines to perform the optimizations.
18. What is the use of static keyword in JavaScript?
Static means, that needs not to initialize multiple times.
If a class have a static method:
- we can call it directly using as classsName.staticMethod().
- we can't access that static method from the class instances.
These are often the utility functions, such as the functions to create or clone any objects.
Example:
class ClassWithStaticMethod
{
static staticMethod() {
return 'You have called a static method.';
}
}
console.log(ClassWithStaticMethod.staticMethod());
// Output: "You have called a static method."
Static method can be called inside the another static method only. (Using this keyword --> this.staticMethod())
Static method can't be called inside the normal methods of the same class.
If we want to call the static method inside the non-static method, we have two tricks to use:
- Call it using the Class Name --> classsName.staticMethod().
- Call it using Constructor of the class --> this.constructor.staticMethod().
19. What is the difference between var and let in JavaScript?
var keyword was introduced from stating in JavaScript.
Let keyword was introduced later in ES6/ES2015
Hoisting:
var: If its been called before initializing, will give undefined.
Let: If its been called before initializing, will throw reference error.
Scope:
var: var scope is limited to the function scope or global scope as its defined.
Let: Let scope is limited to the particular block in which it is defined.
Globally Initialization:
var: If declared globally, it is added in window object, and can also be accessed by
window.variablename
Let: If declared globally, it is not added in window object, and if try to access by
window.variablename will throw error:
Redeclaration:
var: If re-declared, its value is replaced.
Let: If re-declared, it will throw error : Identifier has already been declared.
20. Is JavaScript a case sensitive language?
Yes, a variable with same name having different capitalization of letters will be treated as different variables.