Interview :: JavaScript
21) How to create a function in JavaScript?
22) What are the JavaScript data types?
There are two types of data types in JavaScript:
- Primitive Data Types - The primitive data types are as follows:
- Non-primitive Data Types - The non-primitive data types are as follows:
Data Type | Description |
---|---|
String | represents a sequence of characters, e.g., "hello" |
Number | represents numeric values, e.g., 100 |
Boolean | represents boolean value either false or true |
Undefined | represents an undefined value |
Null | represents null, i.e., no value at all |
Data Type | Description |
---|---|
Object | represents an instance through which we can access members |
Array | represents a group of similar values |
RegExp | represents regular expression |
23) What is the difference between == and ===?
The == operator checks equality only whereas === checks equality, and data type, i.e., a value must be of the same type.
24) How to write HTML code dynamically using JavaScript?
25) How to write normal text code using JavaScript dynamically?
26) How to create objects in JavaScript?
27) How to create an array in JavaScript?
28) What does the isNaN() function?
The isNan() function returns true if the variable value is not a number. For example:
29) What is the output of 10+20+"30" in JavaScript?
3030 because 10+20 will be 30. If there is numeric value before and after +, it treats as binary + (arithmetic operator).
30) What is the output of "10"+20+30 in JavaScript?
102030 because after a string all the + will be treated as string concatenation operator (not binary +).