Unlike most programming languages, the JavaScript language has no concept of input or output. It is designed to run as a
scripting language
in a host environment,eg a browser, and it is up to the host environment to provide mechanisms for communicating with the outside world. JavaScript is an object-oriented dynamic language with types and operators, standard built-in objects, and methods.
borrows most of its syntax from Java, but is also influenced by Awk, Perl and Python. It is an interpreted programming language with object-oriented capabilities. The JavaScript programming language is
part of the Java platform. JavaScript does not create applets or stand-alone applications.
In its most common form, JavaScript resides inside HTML documents,
and can provide levels of interactivity to web pages that are not achievable with simple HTML. Client-side JavaScript does not allow the reading or writing of files. This has been kept for security reason. JavaScript cannot be used for networking applications because there is no such support available. JavaScript doesn't have any multithreading or multiprocessor capabilities. JavaScript ignores spaces, tabs, and newlines that appear in JavaScript programs. JavaScript, allows you to omit this semicolon if each of your statements are placed on a separate line. JavaScript is
. JavaScript's
are: Number String Boolean Symbol (new in Edition 6) Object Function Array Date RegExp null undefined
There are three kinds of declarations in JavaScript.
Declares a variable, optionally initializing it to a value.
Declares a block scope local variable, optionally initializing it to a value.
Declares a read-only named constant.
Javascript comment
is singleline comment Text between the characters
is treated as a comment.
Semicolons are optional
in JavaScript. To create a value, you must merely invoke its name. The main thing to do with numbers is arithmetic. Arithmetic operations such as addition or multiplication take two number values and produce a new number from them. The + and * symbols are called operators.
The primitive boolean type comprises the values true and false. Boolean(12 > 4) // returns true
Script tag
Mostly, JavaScript runs in your web browser alongside HTML and CSS, and can be added to any web page using a script tag. The script tag takes two important attributes -
This attribute specifies what scripting language you are using. You may find this attribute in out dated scripts.
It is obsolete and dont use it for JavaScript.
This attribute is what is now recommended to indicate the scripting language in use and its value should be set to
The older HTML4 standard required this attribute to be set, but HTML5 allows it to be absent.
External scripts
Usually, most JavaScript code is put into an external file, which is attached to HTML, like this:
SCRIPT tags are not case sensitive but Javascript very definitely is.
alert("Hello World") works but Alert("Hello World") makes error. examples: alert("Hello World") confirm("OK or Cancel?") prompt("Favourite Colour?", "Red") <head>
<script type="text/javascript" src=filename.js><script>
</head> The type attribute is not required. JavaScript is the default scripting language in HTML. If src attribute is present then tag contents is ignored. Placing JavaScripts in external files has some advantages: 1 It separates HTML and code 2 It makes HTML and JavaScript easier to read and maintain cached JavaScript files can speed up page loads. Be sure that your JavaScript files (.js) do not include the <script> tag. They should only contain HTML commenting and JavaScript code. x
document.write("Hello World!") document.write can be used to write text, HTML, or a little of both.
var x;
// declaring a variable
x = 3 + y;
// assigning a value to the variable `x`
foo(x, y);
// calling function `foo` with parameters `x` and `y`
// calling method `bar` of object `obj` // A conditional statement if (x === 0) { // Is `x` equal to zero? x = 123; }
Statements Versus Expressions
Statements do things. A program is a sequence of statements. Here is an example of a statement, which declares (creates) a variable foo:
var foo;
Expressions produce values. They are function arguments, the right side of an assignment, etc. Heres an example of an expression:
3 * 7
This statement writes Hello Dolly to the page: document.getElementById("demo").innerHTML = "Hello Dolly."; Use it like this: <p id="demo"></p> <script> document.getElementById("demo").innerHTML = "Hello Dolly."; </script>

JavaScript Display Possibilities
JavaScript can "display" data in different ways: Writing into an alert box, using
. Writing into the HTML output using
. Writing into an HTML element, using
. Writing into the browser console, using
. Semicolons separate JavaScript statements.
Ending statements with semicolon is
not required, but highly
JavaScript ignores multiple spaces. JavaScript statements can be grouped together in code blocks, inside curly brackets {...}.