In computer languages, data types are used to classify a certain type of data. JavaScript is an object-oriented programming language, which means that it is based on the concept of objects and their relationships with one another. It is also a dynamically-typed language, which means that the data type of a variable is determined at runtime rather than at compile-time.
This is significant because the data type you pick will influence the values you can assign to it and the actions you can take with it. To put it another way, ๐๐ป๐ฑ๐ฒ๐ฟ๐๐๐ฎ๐ป๐ฑ๐ถ๐ป๐ด ๐๐ต๐ฒ ๐ฑ๐ฎ๐๐ฎ ๐๐๐ฝ๐ฒ ๐ผ๐ณ ๐ฎ๐ป๐ ๐๐ฎ๐ฟ๐ถ๐ฎ๐ฏ๐น๐ฒ ๐ถ๐ ๐ฐ๐ฟ๐ถ๐๐ถ๐ฐ๐ฎ๐น ๐๐ผ ๐ฝ๐ฒ๐ฟ๐ณ๐ผ๐ฟ๐บ๐ถ๐ป๐ด ๐ผ๐ฝ๐ฒ๐ฟ๐ฎ๐๐ถ๐ผ๐ป๐ ๐๐ถ๐๐ต ๐๐ฎ๐ฟ๐ถ๐ฎ๐ฏ๐น๐ฒ๐ ๐ถ๐ป ๐๐ฎ๐๐ฎ๐ฆ๐ฐ๐ฟ๐ถ๐ฝ๐.

Below are some tricky questions which generally asked during interview specific to JS data type:
๐ฎ.) ๐ช๐ต๐ฎ๐ ๐ฎ๐ฟ๐ฒ ๐๐ต๐ฒ ๐ณ๐ฎ๐น๐๐ ๐ฎ๐ป๐ฑ ๐๐ฟ๐๐๐ต๐ ๐๐ฎ๐น๐๐ฒ๐ ๐ถ๐ป ๐๐ฎ๐๐ฎ๐ฆ๐ฐ๐ฟ๐ถ๐ฝ๐?
There are 6 values that are considered falsy in JavaScript:
- The keyword false
- The primitive value undefined
- The primitive value null
- The empty string (”, “”)
- The global property NaN
- A number or BigInt representing 0 (0, -0, 0.0, -0.0, 0n)
Every other value is considered truthy. It’s important to remember that this applies to all JavaScript values, even ones that might seem falsy, such as empty arrays ([]) or empty objects ({}).
๐ฏ.) ๐๐ ๐ฝ๐น๐ฎ๐ถ๐ป ๐ฝ๐ฎ๐๐๐ฒ๐ฑ ๐ฏ๐ ๐๐ฎ๐น๐๐ฒ ๐ฎ๐ป๐ฑ ๐ฝ๐ฎ๐๐๐ฒ๐ฑ ๐ฏ๐ ๐ฟ๐ฒ๐ณ๐ฒ๐ฟ๐ฒ๐ป๐ฐ๐ฒ ๐ข๐ฅ ๐ช๐ต๐ฎ๐ ๐ถ๐ ๐๐ต๐ฒ ๐ฑ๐ถ๐ณ๐ณ๐ฒ๐ฟ๐ฒ๐ป๐ฐ๐ฒ ๐ฏ๐ฒ๐๐๐ฒ๐ฒ๐ป ๐๐๐ผ๐ฟ๐ฒ๐ฑ ๐ฏ๐ ๐๐ฎ๐น๐๐ฒ(๐ฝ๐ฟ๐ถ๐บ๐ถ๐๐ถ๐๐ฒ) ๐ฎ๐ป๐ฑ ๐๐๐ผ๐ฟ๐ฒ๐ฑ ๐ฏ๐ ๐ฟ๐ฒ๐ณ๐ฒ๐ฟ๐ฒ๐ป๐ฐ๐ฒ (๐ป๐ผ๐ป-๐ฝ๐ฟ๐ถ๐บ๐ถ๐๐ถ๐๐ฒ)?
This can be tricky question to judge how much you are aware about value and reference type. Before that let’s first understand what is pass by value and pass by reference if someone is asking?
What is actually Pass by Value?
Pass by value in JavaScript means that a copy of the actual parameterโs value is made in memory i.e., a new memory allocation is done, and all the changes are made in that new value (i.e., copied value). The original value and the copied value are independent of each other as they both have a different space in memory i.e., on changing the value inside the function, the variable outside the function is not affected.
What is Pass by Reference?
Pass by Reference in JavaScript does not create a new space in the memory, instead, we pass the reference/address of the actual parameter, which means the function can access the original value of the variable. Thus, if we change the value of the variable inside the function, then the original value also gets changed.
Is JS pass by value or pass by reference?
Everything is passed by value, but if your value is an object, then the new scope gets a copy of the reference. If you modify the object by dereferencing, your modifications to the object persist outside of your scope. In JavaScript, there is no such thing as โpass by referenceโ for any variable. All variables and arguments have a value given to them, however the value of an objectโs variable is a reference. As a result, if you supply an object and alter its members inside the method, those changes will remain outside of the function. This makes it appear as if itโs a pass-by-reference system. Primitive values like integer, string, and boolean are provided by value, but objects and arrays, as previously stated, are passed by reference.
๐ฐ.) ๐ป๐๐น๐น ๐ฎ๐ป๐ฑ ๐๐ป๐ฑ๐ฒ๐ณ๐ถ๐ป๐ฒ๐ฑ ๐บ๐ฒ๐ฎ๐ป ๐๐ต๐ฒ ๐๐ฎ๐บ๐ฒ ๐๐ต๐ถ๐ป๐ด?
In simple words, undefined means a variable has been declared but has not yet been assigned a value. undefined is a type by itself (undefined). Unassigned variables are initialized by JavaScript with a default value of undefined.
If a variable is null then it means the variable has no value and that it was explicitly set to have no value by the programmer. A variable will never be null unless somewhere in the code a programmer set a variable to null.
The data type of undefined is undefined whereas that of null is object.ย Also, when used in arithmetic operations,ย undefinedย will result inย NaNย (not a number), whereasย nullย will be converted toย 0ย behind the screens.
We can say that by setting a variable to undefined you are conveying the message that the variable no longer contains any useful information, while if the value is null then you are specifically saying the result of some action has no value.
๐ฑ.) ๐ช๐ต๐ ๐ถ๐ ๐ป๐๐น๐น ๐ฎ๐ป ๐ผ๐ฏ๐ท๐ฒ๐ฐ๐?
In JavaScript, typeof null is ‘object’, which incorrectly suggests that null is an object (it isnโt, itโs a primitive value). This is a bug and one that unfortunately canโt be fixed, because it would break existing codebase. null was a representation of the null pointer. However, there were no pointers in JavaScript like C. So null simply meant nothing or void and was represented by all 0โs. Hence all its 32 bits were 0โs. So whenever the JavaScript interpreter reads null, it considers the first 3 bits as type โobjectโ. That is why typeof null returns โobjectโ.
This may seem like a very obvious bug, but donโt forget that there was very little time to finish the first version of JavaScript. ๐
๐ฒ.) ๐๐ผ๐ ๐๐ผ๐๐น๐ฑ ๐๐ผ๐ ๐ฐ๐ผ๐บ๐ฝ๐ฎ๐ฟ๐ฒ ๐๐๐ผ ๐ผ๐ฏ๐ท๐ฒ๐ฐ๐๐ ๐ถ๐ป ๐๐ฎ๐๐ฎ๐ฆ๐ฐ๐ฟ๐ถ๐ฝ๐?
๐ณ.) ๐๐ณ [] ๐ถ๐ ๐๐ฟ๐๐ฒ, ๐๐ต๐ฒ๐ป []==๐๐ฟ๐๐ฒ ๐๐ต๐ผ๐๐น๐ฑ ๐ฎ๐น๐๐ผ ๐ฏ๐ฒ ๐๐ฟ๐๐ฒ. ๐ฟ๐ถ๐ด๐ต๐?
๐ด.) ๐ช๐ต๐ฎ๐ ๐๐ถ๐น๐น ๐ฏ๐ฒ ๐๐ต๐ฒ ๐ต๐ฎ..๐๐ผ๐ฆ๐๐ฟ๐ถ๐ป๐ด()?
๐ต.) ๐ช๐ต๐ฎ๐ ๐๐ถ๐น๐น ๐ฏ๐ฒ ๐๐ต๐ฒ ๐๐๐ฝ๐ฒ๐ผ๐ณ(๐ก๐ฎ๐ก)?
๐ถ.) ๐๐ผ๐ฒ๐ ๐๐ฎ๐๐ฎ๐ฆ๐ฐ๐ฟ๐ถ๐ฝ๐ ๐๐๐ฝ๐ฝ๐ผ๐ฟ๐ ๐ฎ๐๐๐ผ๐บ๐ฎ๐๐ถ๐ฐ ๐๐๐ฝ๐ฒ ๐ฐ๐ผ๐ป๐๐ฒ๐ฟ๐๐ถ๐ผ๐ป?
๐ท.) ๐ช๐ต๐ฒ๐ฟ๐ฒ ๐ฎ๐ฟ๐ฒ ๐ฟ๐ฒ๐ณ๐ฒ๐ฟ๐ฒ๐ป๐ฐ๐ฒ๐ (๐๐ต๐ถ๐ฐ๐ต ๐ฝ๐ผ๐ถ๐ป๐ ๐๐ผ ๐ผ๐ฏ๐ท๐ฒ๐ฐ๐๐ ๐ฎ๐ป๐ฑ ๐ณ๐๐ป๐ฐ๐๐ถ๐ผ๐ป๐) ๐๐๐ผ๐ฟ๐ฒ๐ฑ? ๐ฆ๐๐ฎ๐ฐ๐ธ ๐ผ๐ฟ ๐๐ฒ๐ฎ๐ฝ?
๐ธ.) ๐๐ถ๐ณ๐ณ๐ฒ๐ฟ๐ฒ๐ป๐ฐ๐ฒ ๐ฏ๐ฒ๐๐๐ฒ๐ฒ๐ป === ๐๐ == ?
There are many more questionsโฆ. where interviewer can ask indirectly about data type. Sometimes people are confused and telling Integer as a data type instead of Number during answer.
I am in process of collating more interviews questions (topic specific) which are basically asked during frontend developer interview and will publish soon on my LinkedIn post.
๐ฃ๐น๐ฒ๐ฎ๐๐ฒ ๐ณ๐ฒ๐ฒ๐น ๐ณ๐ฟ๐ฒ๐ฒ ๐๐ผ ๐ฎ๐ฑ๐ฑ ๐ฎ๐ป๐ ๐พ๐๐ฒ๐๐๐ถ๐ผ๐ป ๐๐ต๐ฎ๐ ๐๐ผ๐ ๐ต๐ฎ๐๐ฒ ๐ฒ๐ป๐ฐ๐ผ๐๐ป๐๐ฒ๐ฟ๐ฒ๐ฑ ๐ฑ๐๐ฟ๐ถ๐ป๐ด ๐๐ผ๐๐ฟ ๐ถ๐ป๐๐ฒ๐ฟ๐๐ถ๐ฒ๐ ๐ถ๐ป ๐ฐ๐ผ๐บ๐บ๐ฒ๐ป๐ ๐๐ฒ๐ฐ๐๐ถ๐ผ๐ป, ๐๐ต๐ถ๐ ๐๐ถ๐น๐น ๐ต๐ฒ๐น๐ฝ ๐ผ๐๐ต๐ฒ๐ฟ ๐ณ๐ฟ๐ผ๐ป๐๐ฒ๐ป๐ฑ ๐ฑ๐ฒ๐๐ฒ๐น๐ผ๐ฝ๐ฒ๐ฟ ๐ท๐ผ๐ฏ ๐ฎ๐๐ฝ๐ถ๐ฟ๐ฎ๐ป๐๐.