1) What is JavaScript?
JavaScript is just like 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.
2) List some features of JavaScript.
there are some features of javascript –
- Lightweight
- Interpreted programming language
- Good for the applications which are network-centric
- Complementary to Java
- Complementary to HTML
- Open source
3) 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.
4) List some of the advantages of JavaScript.
- Server interaction is less
- Feedback to the visitors is immediate
- Interactivity is high
- Interfaces are richer
5) List some of the disadvantages of JavaScript.
- No support for multithreading
- No support for multiprocessing
- Reading and writing of files is not allowed
- No support for networking applications.
6) Define a named function in JavaScript.
function msg()
{
document.writeln("Named Function");
}
msg();
7) Name the types of functions.
for example:
function display()
{
document.writeln("Named Function");
}
display();
They are declared dynamically at runtime.
var display=function()
{
document.writeln("Anonymous Function");
}
display();
8) Define anonymous function
These functions are declared dynamically at runtime using the function operator instead of the function declaration.the function operator 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();
9) Can an anonymous function be assigned to a variable?
Yes, you can assign an anonymous function to a variable.
10) In JavaScript what is an argument object?
The variables of JavaScript represent the arguments that are passed to a function.
11) Define closure.
In JavaScript, we need closures when a variable is defined outside the scope in reference is accessed from some inner scope.
var num = 10;
function sum()
{
document.writeln(num+num);
}
sum();
12) 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.
for example:
var str="Javatpoint";
document.writeln(str.charAt(4));
13) How to write a hello world example of JavaScript?
A simple example of JavaScript hello world is given below. You need to place it inside the body tag of HTML.
<script type="text/javascript">
document.write("JavaScript Hello World!");
</script>
14) What are the key differences between Java and JavaScript? / How is JavaScript different from Java?
JavaScript is a lightweight programming language (most commonly known as scripting language) developed by Netscape, Inc. It is used to make web pages interactive.
A list of key differences between Java and JavaScript.
java
1. Java is a complete and strongly typed programming language used for backend coding. In Java, variables must be declared first to use in the program,
2.Java is an object-oriented programming (OOPS) language or structured programming languages such as C, C++, or .Net.
3.Java creates applications that can run in any virtual machine (JVM) or browser.
4. The Java code needs to be compiled.
5.Java Objects are class-based. You can’t make any program in Java without creating a class.
javascript
1.JavaScript is a weakly typed, lightweight programming language (most commonly known as scripting language)
2.JavaScript is a client-side scripting language, and it doesn’t fully support the OOPS concept.
3.JavaScript code can run only in the browser, but it can now run on the server via Node.js.
4.The JavaScript code doesn’t require to be complied.
5. JavaScript Objects are prototype-based.
15) How to use external JavaScript file?
I am assuming that js file name is message.js, place the following script tag inside the head tag.
<script type="text/javascript" src="message.js"></script>