Three Basic But Tricky JavaScript Questions Which Interviewers Ask
Make sure your basic knowledge of JavaScript is crystal clear
Firstly let us start with a quick introduction on what JavaScript is, so JavaScript or JS is an interpreted language designed by Brendan Erich which follows ECMAScript standards which is a globalised standard for scripting programming languages.
In today's modern era, JavaScript is one of the most important programming languages. It is used to add various functionalities and enhance the user interactivity with a website and all the current websites which we use are hugely dependent on JavaScript.
We can’t simply use HTML to create a dynamic website, although you can build a website using HTML easily it will always be static and the use of JavaScript becomes important for making it dynamic.
It is obvious due to its huge popularity many developers prefer to learn JavaScript for their future careers but the only mistake they make is they rush to intermediate and advanced concepts without going deep into the basic concepts.
So let’s check out a few very basic, but tricky and important JavaScript questions which you must know as a web developer —
What are the Data Types in JavaScript?
This is a very basic question which many young developers get confused in answering. I have heard answers like char
is a data type in JavaScript which is completely wrong and shows that you are not that aligned with the basics of the programming language.
I believe developers make mistakes answering this question because of their vibrant background with different programming languages.
When you know a programming language already before learning JavaScript then things do get easier you can grasp 80% of the content quite earlier but you need to make sure of the difference between the basics of the different programming languages.
Yes char
is a data type which is available in almost every programming language but not in JavaScript.
There are 7 Primitive Data Types in JavaScript and 1 Non Primitive Data Type in JavaScript according to official documentation by Mozilla.
To name the 7 Primitive Data Types in JavaScript they are Bool
, String
, Number,
BigInt
, Undefined
, Null
, and Symbol
and as for the one with Non Primitive it is Object
.
What are the standard naming conventions for Variables in JavaScript?
This is a must-ask question which an interviewer asks, typically it is just to check what coding and naming convention a candidate knows so he can fit in with other co-workers.
If you reply by I don’t follow any rules and I have a different naming convention which only suits me, trust me mate you will be rejected right away.
Imagine you want to work with a team of ten people who have a task to work on a single code, how difficult it can be for them to understand your code if you are not using standard coding conventions and naming conventions?
The most important convention to name a variable is to use camel case and the variable names you are using should be sensible like firstName
, lastName
instead of f
and l
, this is the most primary knowledge you must have.
Along with this, to name your variable you must know you can’t use a keyword which is already there in JavaScript, it will throw an error and similarly, you can’t start a variable name with numbers. Also, you can’t use spaces between your variable name, it is not valid.
If you are asked which symbols you can use while declaring variables then there are only two symbols mainly $
and _
, note that other symbols will throw an error or the code will treat it as something else.
Can you define an Array in JavaScript?
I know many people surge with confidence when they hear the word “array”, it’s because in our college we have studied extensively about array for different programming languages so it would be an easy topic for many.
Whenever this question is asked, many times people usually tend to answer that arrays are used to store data which are of similar types and to be honest it is true but completely incorrect when it comes to JavaScript.
Unlike other programming languages you can combine different data types into a single array, isn’t this interesting?
You can declare an array as follows in JavaScript and it is completely valid —
var firstArray = ["Aniket", "Z", 5]
Whether the element firstArray
is a string or number it is a valid case and is a standard convention in JavaScript.
Remember if you are looking for an entry-level job opportunity or internship, instead of focusing on multiple things focus on clearing your basics. Most of the time interviewer only cares how strong is your basic knowledge because when you join the job you will be learning advanced concepts from scratch.
Focus on practising every day and making appropriate notes for coding concepts, best of luck in your programming journey!
In Plain English 🚀
Thank you for being a part of the In Plain English community! Before you go:
- Be sure to clap and follow the writer ️👏️️
- Follow us: X | LinkedIn | YouTube | Discord | Newsletter
- Visit our other platforms: Stackademic | CoFeed | Venture
- More content at PlainEnglish.io