[Go to site: main page, start]

0% found this document useful (0 votes)
12 views16 pages

Understanding JavaScript Basics

JavaScript is a lightweight, object-oriented programming language used for scripting webpages, enabling dynamic interactivity in web applications. It supports various features such as weak typing, prototype-based inheritance, and is compatible with multiple operating systems. JavaScript is utilized for client-side validation, dynamic content, and includes different data types, operators, and commenting styles.

Uploaded by

ememem9090e
Copyright
© All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
12 views16 pages

Understanding JavaScript Basics

JavaScript is a lightweight, object-oriented programming language used for scripting webpages, enabling dynamic interactivity in web applications. It supports various features such as weak typing, prototype-based inheritance, and is compatible with multiple operating systems. JavaScript is utilized for client-side validation, dynamic content, and includes different data types, operators, and commenting styles.

Uploaded by

ememem9090e
Copyright
© All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd

What is JavaScript

JavaScript (js) is a light-weight object-oriented programming language which is used by several websites for
scripting the webpages. It is an interpreted, full-fledged programming language that enables dynamic interactivity
on websites when applied to an HTML document. It was introduced in the year 1995 for adding programs to the
webpages in the Netscape Navigator browser. Since then, it has been adopted by all other graphical web browsers.
With JavaScript, users can build modern web applications to interact directly without reloading the page every
time. The traditional website uses js to provide several forms of interactivity and simplicity.

Features of JavaScript
There are following features of JavaScript:

➢ All popular web browsers support JavaScript as they provide built-in execution environments.
➢ JavaScript follows the syntax and structure of the C programming language. Thus, it is a structured
programming language.
➢ JavaScript is a weakly typed language, where certain types are implicitly cast (depending on the operation).
➢ JavaScript is an object-oriented programming language that uses prototypes rather than using classes for
inheritance.
➢ It is a light-weighted and interpreted language.
➢ It is a case-sensitive language.
➢ JavaScript is supportable in several operating systems including, Windows, macOS, etc.
➢ It provides good control to the users over the web browsers.

Application of JavaScript
JavaScript is used to create interactive websites. It is mainly used for:

➢ Client-side validation,
➢ Dynamic drop-down menus,
➢ Displaying date and time,
➢ Displaying pop-up windows and dialog boxes (like an alert dialog box, confirm dialog box and prompt dialog
box),
➢ Displaying clocks etc.
JavaScript Comment

The JavaScript comments are meaningful way to deliver message. It is used to add information about the code,
warnings or suggestions so that end user can easily interpret the code.

The JavaScript comment is ignored by the JavaScript engine i.e. embedded in the browser

Types of JavaScript Comments


There are two types of comments in JavaScript.

➢ Single-line Comment
➢ Multi-line Comment

JavaScript Single line Comment

It is represented by double forward slashes (//). It can be used before and after the statement.
Let’s see the example of single-line comment i.e. added before the statement.

<script>

// It is single line comment

[Link]("hello javascript");

</script>

JavaScript Multi line Comment

It can be used to add single as well as multi line comments. So, it is more convenient.

It is represented by forward slash with asterisk then asterisk with forward slash. For example:

<script>

/* It is multi line comment.

It will not be displayed */

[Link]("example of javascript multiline comment");

</script>

JavaScript Variable
A JavaScript variable is simply a name of storage location. There are two types of variables in JavaScript : local
variable and global variable.
➢ There are some rules while declaring a JavaScript variable (also known as identifiers).
➢ Name must start with a letter (a to z or A to Z), underscore( _ ), or dollar( $ ) sign.
➢ After first letter we can use digits (0 to 9), for example value1.
➢ JavaScript variables are case sensitive, for example x and X are different variables.

EXAMPLE

<script>

var x = 10;

var y = 20;

var z=x+y;

[Link](z);

</script>

JavaScript local variable

A JavaScript local variable is declared inside block or function. It is accessible within the function or
block only. For example:

<script>
<script>
function abc(){
If(10<13){
var x=10;//local variable
var y=20;//JavaScript local variable
}
}
</script>
</script>
JavaScript global variable

A JavaScript global variable is accessible from any function. A variable i.e. declared outside the function
or declared with window object is known as global variable. For example:

<script>

var data=200;//gloabal variable

function a(){

[Link](data);

function b(){

[Link](data);

a();//calling JavaScript function

b();

</script>

JavaScript Global Variable

A JavaScript global variable is declared outside the function or declared with window object. It can be
accessed from any function.

Let’s see the simple example of global variable in JavaScript.

<script>

var value=50;//global variable

function a(){

alert(value); }

function b(){

alert(value);

</script>
Java script Data Types

JavaScript provides different data types to hold different types of values. There are two types of data types
in JavaScript.

➢ Primitive data type


➢ Non-primitive (reference) data type

JavaScript is a dynamic type language, means you don't need to specify type of the variable because it is
dynamically used by JavaScript engine. You need to use var here to specify the data type. It can hold any
type of values such as numbers, strings etc. For example:

var a=40;//holding number

var b="Rahul";//holding string


<script>

let x; // Now x is undefined

x = 5; // Now x is a Number

x = "John"; // Now x is a String

<script>

JavaScript Operators:

There are following types of operators in JavaScript.


➢ Arithmetic Operators
➢ Comparison (Relational) Operators
➢ Bitwise Operators
➢ Logical Operators
➢ Assignment Operators
➢ Special Operators
JavaScript Arithmetic Operators

Arithmetic operators are used to perform arithmetic operations on the operands. The following operators
are known as JavaScript arithmetic operators.

JavaScript Addition

The Addition Operator (+) adds numbers:

<script>

let x = 5;

let y = 2;

let z = x + y;

[Link]("demo").innerHTML = z;

</script>

JavaScript Multiplication

The Multiplication Operator (*) multiplies numbers:

<script>

let x = 5;

let y = 2;

let z = x * y;

[Link]("demo").innerHTML = z;

</script>
Subtracting

The subtraction operator (-) subtracts numbers.

<script>

let x = 5;

let y = 2;

let z = x - y;

[Link]("demo").innerHTML = z;

</script>

Multiplying
The multiplication operator (*) multiplies numbers.

<script>

let x = 5;

let y = 2;

let z = x * y;

[Link]("demo").innerHTML = z;

</script>

Dividing

The division operator (/) divides numbers.

<script>

let x = 5;

let y = 2;

let z = x / y;

[Link]("demo").innerHTML = z;

</script>
Remainder

The modulus operator (%) returns the division remainder.

<script>

let x = 5;

let y = 2;

let z = x % y;

[Link]("demo").innerHTML = z;

</script>

Incrementing

The increment operator (++) increments numbers.

<script>

let x = 5;

x++;

let z = x;

[Link]("demo").innerHTML = z;

</script>

Decrementing
The decrement operator (--) decrements numbers.

<script>

let x = 5;

x--;

let z = x;

[Link]("demo").innerHTML = z;

</script>
JavaScript Comparison Operators

Comparison operators compare two values and give back a boolean value: either true or
false. Comparison operators are used in decision making and loops.
JavaScript Bitwise Operators
The bitwise operators perform bitwise operations on operands. The bitwise operators are as follows:-

You might also like