Beginner Level Javascript Interview Questions and Answers For Freshers
Beginner Level Javascript Interview Questions and Answers For Freshers
sections:
• Beginner Level
• Intermediate Level
• Advanced Level
Let’s begin with the first section of JavaScript interview
questions.
Java JavaScript
JavaScript is an OOP
Java is an OOP programming language.
scripting language.
It creates applications that run in a The code is run on a browser
virtual machine or browser. only.
JavaScript code are all in
Java code needs to be compiled.
the form of text.
Q2. What is JavaScript?
JavaScript is a lightweight, interpreted programming language with
• Undefined
• Null
• Boolean
• String
• Symbol
• Number
• Object
• It is a lightweight, interpreted programming
language.
var emp = {
name: "Daniel",
age: 23
};
var x = [];
var y = [1, 2, 3, 4, 5];
be defined using functionkeyword as :
function named(){
// write code here
}
Q10. Can you assign an anonymous function to a variable
and pass it as an argument to another function?
Yes! An anonymous function can be assigned to a variable. It can
section below.
function func(x){
console.log(typeof x, arguments.length);
}
func(); //==> "undefined", 0
func(7); //==> "number", 1
func("1", "2", "3"); //==> "string", 3
Q14. What is Callback?
A callback is a plain JavaScript function passed to some method as
Built-in
Values
Method
CharAt() It returns the character at the specified index.
Concat() It joins two or more strings.
forEach() It calls a function for each element in the array.
It returns the index within the calling String object
indexOf()
of the first occurrence of the specified value.
length() It returns the length of the string.
It removes the last element from an array and returns
pop()
that element.
It adds one or more elements to the end of an array
push()
and returns the new length of the array.
reverse() It reverses the order of the elements of an array.
In case you are facing any challenges with these JavaScript
section below.
JavaScript:
•.1
You should not use any of the
JavaScript reserved keyword as variable name.
For example, break or boolean variable names
are not valid.
•.2
JavaScript variable names should not start with
a numeral (0-9). They must begin with a letter
or the underscore character. For example,
123name is an invalid variable name but
_123name or name123 is a valid one.
•.3
JavaScript variable names are case sensitive .
For example, Test and test are two different
variables.
placed before its single operand, which can be of any type. Its
Syntax :
cookie path to ensure that you delete the right cookie. Some
browsers will not let you delete a cookie if you don’t specify the
path.
questions.
value=’Name’ etc.
Javascript code:
• Inline
• Internal
• External
An inline function is a JavaScript function, which is assigned to
script integrated in the page you are working on, or you can have
Local Storage 21 03 The data is not sent back to the server for every
HTTP request (HTML, images, JavaScript, CSS, etc) 20
13 reducing the
time, data stored in session storage gets cleared when the page
session ends. Session Storage will leave when the browser is
closed.
section below.
that, but === doesn’t allow that, because it not only checks the
value but also type of two variable, if two variables are not of
the same type “===” return false, while “==” return true.
value. Also, undefined and null are two distinct types: undefined
have not been given any value. If the program tries to read the
• Angular
• React
• Vue
Q32. What is the difference between window & document in
JavaScript?
Window Document
JavaScript window is a global The document also comes under the
object which holds variables, window and can be considered as
functions, history, location. the property of the window.
Q33. What is the difference between innerHTML & innerText?
innerHTML 21 03 It will process an HTML tag if found in a string
Then the execution passes to its parent element and so on till the
body element.
section below.
string.
For example-
parseInt("4F", 16)
Using Imports and exports we can split our code into multiple
Questions.
code.
that prompts the visitor for input. A prompt box is often used if
you want the user to input a value before entering a page. When a
prompt box pops up, the user will have to click either “OK” or
“Cancel” to proceed after entering an input value.
var Y = 1;
if (function F(){})
{
y += Typeof F;</span>
}
console.log(y);
Syntax-
Syntax-
fun.apply(thisArg, [argsArray])
Q44. How to empty an Array in JavaScript?
Method 1 –
arrayList = []
Above code will set the variable arrayList to a new empty array.
emptying the array, because if you have referenced this array from
unchanged.
Method 2 –
arrayList.length = 0;
The code above will clear the existing array by setting its length
Method 3 –
arrayList.splice(0, arrayList.length);
emptying the array will also update all the references to the
original array.
Method 4 –
while(arrayList.length)
{
arrayList.pop();
}
section below.
delete the foo property from object x. After doing so, when we try
The output would be xyz. Here, emp1 object has company as its
For example-
section and we’ll answer them. You can also comment below if you
have any questions in your mind, which you might face in your
JavaScript interview.