JS All Flashcards
What is JavaScript?
JavaScript is a scripting language. Different from Java. 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
Interpreted programming language
Good for the applications which are network-centric
Complementary to Java
Complementary to HTML
Open source
Cross-platform
Who developed JavaScript
Developed by Brendan Eich, 1995 Mocha - Live Script - Java Script
Some of the advantages of JavaScript.
Server interaction is less
Feedback to the visitors is immediate
Interactivity is high
Interfaces are richer
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.
Define a named function in JavaScript.
The function which has named at the time of definition is called a named function.
~~~
function msg()
{
document.writeln(“Named Function”);
}
msg();
~~~
Name the types of functions
The types of function are:
Named - These type of functions contains name at the time of definition.
~~~
function display()
{
document.writeln(“Named Function”);
}
display();
Anonymous - These type of functions doesn’t contain any name. They are declared dynamically at runtime.
var display=function()
{
document.writeln(“Anonymous Function”);
}
display();
~~~
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.
~~~
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.
10) In JavaScript what is an argument object?
The variables of JavaScript represent the arguments that are passed to a function.
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?
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));
Difference between JavaScript and JScript?
JScript is the same as JavaScript, but Microsoft provides it.
hello world example of JavaScript?
You need to place it inside the body tag of HTML.
<script type="text/javascript"> document.write("JavaScript Hello World!"); </script>
What are the key in Java?
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, and the type of a variable is checked at compile-time.
Java is an object-oriented programming (OOPS) language or structured programming languages such as C, C++, or .Net.
Java creates applications that can run in any virtual machine (JVM) or browser.
The Java code needs to be compiled.
Java Objects are class-based. You can’t make any program in Java without creating a class.
Java is a Complete and Standalone language that can be used in backend coding.
Java programs consume more memory.
The file extension of the Java program is written as “.Java” and it translates source code into bytecodes which are then executed by JVM (Java Virtual Machine).
Java supports multithreading.
Java uses a thread-based approach to concurrency.
What are the key in Java Script?
JS is a weakly typed, lightweight programming language and has more relaxed syntax and rules.
JS is a client-side scripting language, and it doesn’t fully support the OOPS concept. It used to make web pages interactive .
JS code can run only in the browser, but it can now run on the server via Node.js.
The JS code doesn’t require to be complied.
JS Objects are prototype-based.
JS is assigned within a web page and integrates with its HTML content.
JS code is used in HTML web pages and requires less memory.
The JS file extension is written as “.js” and it is interpreted but not compiled. Every browser has a JS interpreter to execute the JS code.
JS doesn’t support multithreading.
JS uses an event-based approach to concurrency.
How to use external JavaScript file?
js file name is message.js, place the following script tag inside the head tag.
<script type="text/javascript" src="message.js"></script>
Is JavaScript case sensitive language?
Yes, JavaScript is a case sensitive language.
~~~
Var msg = “JavaScript is a case-sensitive language”; //Here, var should be used to declare a variable
function display()
{
document.writeln(msg); // It will not display the result.
}
display();
~~~
What is BOM?
BOM stands for Browser Object Model. It provides interaction with the browser. The default object of a browser is a window. So, you can call all the functions of the window by specifying the window or directly. The window object provides various properties like document, history, screen, navigator, location, innerHeight, innerWidth,
What is DOM? What is the use of document object?
DOM stands for Document Object Model. A document object represents the HTML document. It can be used to access and change the content of HTML.
What is the use of window object?
The window object is created automatically by the browser that represents a window of a browser. It is not an object of JavaScript. It is a browser object.
The window object is used to display the popup dialog box.
Method Description
alert() displays the alert box containing the message with ok button.
confirm() displays the confirm dialog box containing the message with ok and cancel button.
prompt() displays a dialog box to get input from the user.
open() opens the new window.
close() closes the current window.
setTimeout() performs the action after specified time like calling function, evaluating expressions.
What is the use of history object?
The history object of a browser can be used to switch to history pages such as back and forward from the current page or another page. There are three methods of history object.
history.back() - It loads the previous page.
history.forward() - It loads the next page.
history.go(number) - The number may be positive for forward, negative for backward. It loads the given page number.
How to write a comment in JavaScript?
There are two types of comments in JavaScript.
Single Line Comment: It is represented by // (double forward slash)
Multi-Line Comment: Slash represents it with asterisk symbol as /* write comment here */
How to create a function in JavaScript?
Create a function in JavaScript, follow the following syntax.
function function_name(){ //function body }
This is heading using JavaScript
"; ```Date is: "+day+"/"+month+"/"+year); } display(); ```
"); } } display(); ```
"); document.writeln(ws.has(obj2)); } display() ```
"); document.writeln(map.get(2)+"
"); document.writeln(map.get(3)); } display(); ```