Professional Documents
Culture Documents
Read
Discuss
Practice
Video
Courses
JavaScript (JS) is the world’s most popular lightweight, interpreted compiled programming
language. It is also known as a scripting language for web pages. It can be used for Client-
side as well as Server-side developments.
<script>
// Function definition
function MyFunction() {
console.log(Name);
console.log("\n" + num);
// Function call
MyFunction();
</script>
JavaScript is the most popular programming language for both client-side and server-side to
make interactive web pages. It is mainly used to develop websites and web-based applications.
Creating Interactive Websites: JavaScript is used to make the web pages dynamic and
interactive. It means using JavaScript, we can change the web page content and styles
dynamically.
Building Applications: JavaScript is used to make web and mobile applications. To
build the web and mobile apps, we can use most popular JavaScript frameworks like –
ReactJS, React Native, Node.js etc.
Web Servers: We can make robust server applications using JavaScript. To be precise
we use JavaScript frameworks like Node.js and Express.js to build these servers.
Game Development: JavaSCript can be used to design Browser games. In JavaScript,
lots of game engines available that provide frameworks for building games.
JavaScript is the most popular and hence the most loved language around the globe. Apart from
this, there are abundant reasons to learn it. Below are a listing of few important points:
No need of compilers: Since JavaScript is an interpreted language, therefore it does not
need any compiler for compilations.
Used both Client and Server-side: Earlier JavaScript was used to build client-side
applications only, but with the evolution of its frameworks namely Node.js and
Express.js, it is now widely used for building server-side applications too.
Helps to build a complete solution: As we saw, JavaScript is widely used in both
client and server-side applications, therefore it helps us to build an end-to-end solution
to a given problem.
Used everywhere: JavaScript is so loved because it can be used anywhere. It can be
used to develop websites, games or mobile apps, etc.
Huge community support: JavaScript has a huge community of users and mentors
who love this language and take it’s legacy forward.
Introduction to JavaScript
Where to put JavaScript code in an HTML Document ?
Introduction to JavaScript Course
Introduction to Object Oriented Programming in JavaScript
Top 5 JavaScript Projects For Beginners
How to Become a JavaScript Developer?
7 JavaScript Concepts That Every Web Developer Should Know
JavaScript Backend basics
Advanced JavaScript Backend Basics
Functional Programming in JavaScript
Top 5 Reasons to Learn JavaScript
This section contains the list of all properties and methods of all JavaScript objects.
Array
ArrayBuffer
Atomics
BigInt
Boolean and dataView
Date
Error
Function
Generator
Intl
JSON
Map
Math
Number
Object
JavaScript
Proxy
Reflect
RegExp
String
Symbol
WeakMap
WeakSet
Expressions
<!DOCTYPE html>
<html lang="en">
<head>
<title>
Basic Example to Describe JavaScript
</title>
</head>
<body>
<!-- JavaScript code can be embedded inside
head section or body section -->
<script>
console.log("Welcome to GeeksforGeeks");
</script>
</body>
</html>
<!DOCTYPE HTML>
<html>
<head>
<title></title>
</head>
<body>
<script>
</script>
</body>
</html>
Javascript
<script>
// using console.log
console.log('Hello World');
</script>
<!DOCTYPE html>
<html>
<body>
<h2>W3schools Online HTML editor</h2>
<script>
document.write("Hello Test!");
</script>
</body>
</html>
JavaScript is an object-based client-side scripting language that is popular and used to create
dynamic and interactive web pages. Javascript is an interpreted language usually used with
HTML, and programs written in JavaScript are called lightweight scripts.
Earlier, JavaScript was named LiveScript, but later, Netscape changed its name to JavaScript
because its origin was from Java which was very popular at that time. JavaScript released its
first look for Netscape 2.0 under the name "LiveScript" in 1995.
JavaScript can interact with HTML DOM elements and dynamically control the webpage.
Client-side validation in the webpage is done using JavaScript.
Components such as drop-down menus, pop-up windows, dialog boxes, etc., are created using
JavaScript.
Javascript is used to load data asynchronously without refreshing the webpage.
JavaScript is used extensively in the development of online games.
Advantages of JavaScript
Speed: JavaScript is a client-side scripting language. It is fast because all its code functions
run immediately on the client machine instead of contacting the server and waiting for a
response.
Simplicity: JavaScript is relatively easy to learn and code.
Versatility: JavaScript works well with other languages and is utilized in various applications.
Server Load: Being on the client side reduces the requirement on the website server.
What Does the Script Mean?
A script is a set of instructions given in the form of code. Instructions are designed for either
the web browser (client-side scripting) or the server (server-side scripting). Scripts provide
changes to the web page.
About Us
Purpose of JavaScript
When JavaScript first appeared in 1995, with effective use of handling some of the input
validation that had previously been left over to server-side languages like Perl. Before that
time, the server required a round-trip to determine whether a required field was left blank or
an invalid value entered. Netscape Navigator wanted to change that with the introduction of
JavaScript. The potential and ability to handle some necessary validation on the client was an
exciting fresh feature when telephone modems were common and well known. The
associated slow speeds turned every trip to the server into an exercise in patience.
Gradually Microsoft became a mortal threat, compelling Netscape with its Internet Explorer.
Slowly, a standardization process started to develop to prevent Microsoft from gaining the
power of the JavaScript language. Furthermore, they partnered with Sun to influence their
shared interest in breaking the Microsoft monopoly.
Brendan Eich has assumed that Sun on board decided to surf the tidal wave of building up
surrounding Java and position JavaScript as the companion language with Java, in a similar
manner, Visual Basic was to C++. Netscape's Mocha was later named JavaScript and aimed
to turn the web into a full-blown application platform.
Unfortunately for JavaScript, its early marketing position outlasted its usefulness and later
became a mark on market acceptance because it emerged as a viable technology.
More on JavaScript
Since then, JavaScript has become a significant feature of every main web browser on the
market. No longer bound to simple data validation, JavaScript now interacts and works with
nearly all aspects of the browser window and its contents. JavaScript is recognized as a
complete programming language that can handle complex calculations and interactions,
including closures, anonymous (lambda) functions, and meta-programming. JavaScript has
become such an essential element of the web that even alternative browsers, including those
browsers that run on mobile phones and those designed for users with disabilities, support
and maintain it. Even Microsoft, with its client-side scripting language called VBScript,
ended up with its JavaScript implementation in Internet Explorer from its initial version.
About Us
The introduction of JavaScript into web pages immediately ran into the Web's
primary language, HTML. As the component of its original work on JavaScript,
Netscape tried to find out how to make JavaScript coexist in HTML pages without
causing any breaks on those pages, rendering in other browsers. Through trial and
error and controversy, several decisions were finally made and agreed upon to bring
universal scripting support to the Web. Most of the work done in these early days of
the Web has endured and become official in the HTML specification. In this chapter,
you will relate the JavaScript language with HTML.
Attribute Description
async Which indicates that the script ought to begin downloading immediately.
charset Set the character set of the code particularizes using the src attribute.
defer It indicates that the execution of the script can safely be deferred until after the document's content has be
and displayed.
language Which indicates that the code is using the scripting language.
src Which indicates that an external file that holds the code is to be executed.
type is used to replace language; indicates the content type (also called MIME type) of the used scripting languag
Example:
function test() {
alert("Hello Test!");
}
JavaScript Placement Within HTML
Traditionally, all <script> elements were positioned within the <head> element on an
HTML document's page, such as in the example given below:
Example:
<!DOCTYPE html>
<html>
<head>
<title>Webpage Title</title>
<script src="example1.js"></script>
<script src="example2.js"></script>
</head>
<body>
<!- - contents here -->
</body>
</html>
The primary purpose of this structuring was to keep external file references, both CSS
and JavaScript files, in the exact location. Moreover, including all JavaScript files in
the <head> of a document designates that all of the JavaScript code must have to be
downloaded, then parsed and interpreted before the page begins rendering. Rendering
means the moment when the browser receives the opening <body> tag in an HTML
code. For pages that require a lot of JavaScript code, this can cause a noticeable delay
in page rendering, during which time the browser will be entirely blank.
Example:
<!DOCTYPE html>
<html>
<head>
<title>Webpage Title</title>
<script defer src="example1.js"></script>
<script defer src="example2.js"></script>
</head>
<body>
<!-- contents here -->
</body>
</html>
JavaScript Keywords must be in your information because you can not use them as a
variable name.
If implements In Instanceof
impor Super
t
❮ Previous Page Print PageNext Page ❯
Object-oriented (OO) languages usually are recognized through their use of classes for
creating various objects which have similar properties and methods. It is to be noted that
ECMA-Script has no concept of classes, and hence objects are different than in class-based
languages.
Understanding Objects
The simplest way to create a custom object is to create a new instance of the object and add
properties and methods to it, as in the example mentioned below:
The previous example can be rewritten using literal object notation as follows:
var person = {
name: "Karlos",
age: 23,
job: "Network Engineer",
say_Name: function() {
alert(this.name);
}
};
The person object in the above example is equivalent to the object in the previous example,
with all those same properties and methods added. These properties are all created with
specific characteristics that define their behavior in JavaScript.
Obj_Name.obj_Property = property_Value;
Example:
Although ECMA-Script defines it as the core of JavaScript, the Browser Object Model
(BOM) is the central part of using JavaScript on the Web. This chapter will teach you about
the browser object model, window-related objects and frames, positions, and more.
function say_Age() {
alert(this.age);
}
alert(window.age); //26
say_Age(); //26
window.say_Age(); //26
In the above example, a variable named 'age' and a function named 'say_Age()' is classified in
the global scope that automatically places them on the window object. So, the variable age is
also accessible as window .age, and the function say_Age() is also accessible
via window.sayAge().
<html>
<head>
<title>Frameset Example</title>
</head>
<frameset rows="150,*">
<frame src="frame1.html" name="top_Frame">
<frameset cols="60%,60%">
<frame src="another_frame.html" name="left_Frame">
<frame src="yetAnother_frame.html" name="right_Frame">
</frameset>
</frameset>
<noframes></noframes>
</html>
The above code snippet generates a frameset having one frame across the top and two frames
below. Also, the top frame can be referenced by window.frames[0] or window.frames ["top_Frame"].
Though, you would most likely use the top object instead of a window to refer to these
frames (creating its top .frames[0], for instance). The top object always points to the very top
(outermost) frame, which is the browser window itself.