JavaScript Interview Questions
Categories: Java 8(JDK1.8)
What is JavaScript?
JavaScript is a scripting language. It is different from Java language. It is object-based, lightweight, cross-platform translated language. It is widely used for client-side validation. The JavaScript Translator (embedded in the browser) is responsible for translating the JavaScript code for the web browser.
List some features of JavaScript.
Some of the features of JavaScript are:
a) Lightweight
b) Interpreted programming language
c) Good for the applications which are network-centric
d) Complementary to Java
e) Complementary to HTML
Who developed JavaScript, and what was the first name of JavaScript?
JavaScript was developed by Brendan Eich, who was a Netscape programmer. Brendan Eich developed this new scripting language in just ten days in the year September 1995. At the time of its launch, JavaScript was initially called Mocha. After that, it was called Live Script and later known as JavaScript.
List some of the advantages of JavaScript.
Some of the advantages of JavaScript are:
a) Server interaction is less
b) Feedback to the visitors is immediate
c) Interactivity is high
d) Interfaces are richer
List some of the disadvantages of JavaScript.
Some of the disadvantages of JavaScript are:
a) No support for multithreading
b) No support for multiprocessing
c) Reading and writing of files is not allowed
d) No support for networking applications.
Define a named function in JavaScript.
The function which has named at the time of definition is called a named function. For example
function msg()
{
document.writeln("Named Function");
}
msg();
Define anonymous function
It is a function that has no name. These functions are declared dynamically at runtime using the function operator instead of the function declaration. The function operator is more flexible than a function declaration. It can be easily used in the place of an expression. For example:
var display=function()
{
alert("Anonymous Function is invoked");
}
display();
Can an anonymous function be assigned to a variable?
Yes, you can assign an anonymous function to a variable.
Define closure.
In JavaScript, we need closures when a variable which is defined outside the scope in reference is accessed from some inner scope.
var num = 10;
function sum()
{
document.writeln(num+num);
}
sum();
If we want to return the character from a specific index which method is used?
The JavaScript string charAt() method is used to find out a char value present at the specified index. The index number starts from 0 and goes to n-1, where n is the length of the string. The index value can't be a negative, greater than or equal to the length of the string. For example:
var str="Javatpoint";
document.writeln(str.charAt(4));
What is the difference between JavaScript and JScript?
Netscape provided the JavaScript language. Microsoft changed the name and called it JScript to avoid the trademark issue. In other words, you can say JScript is the same as JavaScript, but Microsoft provides it.