Maybe you should know all of them but i dont care honestly :)I write them for my self for the next interviews maybe and just this .
What are data types in javascript?
Data Types | Description | Example |
---|---|---|
String | Represents textual data | let str = 'Hi', let str2 = "Hello", let str3 = Hello World |
Number | An integer or a floating-point number | let num = 3, let num2 = 3.234, let num3 = 3e-2 |
BigInt | An integer with arbitrary precision | let num = 900719925124740999n, let num = 1n |
Boolean | Any of two values: true or false | let flag = true |
undefined | A data type whose variable is not initialized | let a; |
null | Denotes a null value | let a = null; |
Symbol | Data type whose instances are unique and immutable | let value = Symbol('hello'); |
Object | key-value pairs of collection of data | let student = { }; |
What is difference between null
vs undefined
?
Null | Undefined |
---|---|
It is an assignment value which indicates that variable points to no object. | It is not an assignment value where a variable has been declared but has not yet been assigned a value. |
Type of null is object | Type of undefined is undefined |
The null value is a primitive value that represents the null, empty, or non-existent reference. | The undefined value is a primitive value used when a variable has not been assigned a value. |
Indicates the absence of a value for a variable | Indicates absence of variable itself |
Converted to zero (0) while performing primitive operations | Converted to NaN while performing primitive operations |
what is delete Operator ?
The delete keyword is used to delete the property as well as its value.
Ex:
var user = {name: "sadaf amininia", age: 25”}; delete user.age;
console.log(user); // {name: "sadaf amininia"}
const f = null;
console.log(typeof f); // "object"
const g = undefined;
console.log(typeof g); // "undefined"
const h = { b: "c" };
console.log(typeof h); // "object"
const i = function () {
return 10;
};
console.log(typeof i); // "function"
Slice vs splice ?
Slice | Splice |
---|---|
Doesn't modify the original array(immutable) | Modifies the original array(mutable) |
Returns the subset of original array | Returns the deleted elements as array |
Used to pick the elements from array | Used to insert or delete elements to/from array |
Is two arrays or Obj equals in Js?
In JavaScript, two objects or arrays are not considered equal just by having the same properties or elements. They are only equal if they reference the same object or array in memory. To compare the values of two objects or arrays, you need to iterate through their properties or elements and compare each one individually.