0% found this document useful (0 votes)
293 views

javascript intro

JavaScript is a lightweight, object-oriented programming language primarily used for creating interactive web pages. It supports various features including client-side validation, dynamic content, and is compatible with all popular web browsers. The language includes multiple data types, operators, and allows for both local and global variable declarations.
Copyright
© © All Rights Reserved
Available Formats
Download as PPTX, PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
293 views

javascript intro

JavaScript is a lightweight, object-oriented programming language primarily used for creating interactive web pages. It supports various features including client-side validation, dynamic content, and is compatible with all popular web browsers. The language includes multiple data types, operators, and allows for both local and global variable declarations.
Copyright
© © All Rights Reserved
Available Formats
Download as PPTX, PDF, TXT or read online on Scribd
You are on page 1/ 28

JavaScript

JavaScript:

JavaScript (js) is a light-weight object-oriented programming


language which is used by several websites for scripting the web pages.
It is an interpreted, full-fledged programming language that enables
dynamic interactivity on websites when applied to an HTML document.

It was invented by Brendan Eich.

JavaScript is versatile and beginner-friendly. With more


experience, you'll be able to create games, animated 2D and 3D graphics,
comprehensive database-driven apps, and much more.
JavaScript has no connectivity with Java programming language.
The name was suggested and provided in the times when Java was gaining
popularity in the market.

Features of JavaScript

1. All popular web browsers support JavaScript.


2. JavaScript follows the syntax and structure of the C programming
language.
3. JavaScript is an object-oriented programming language.
4. It is a light-weighted and interpreted language.
5. It is a case-sensitive language.
6. JavaScript is supportable in several operating systems and 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


1. Client-side validation
2. Displaying pop-up windows and dialog boxes
3. Displaying date and time,
4. Dynamic drop-down menus,
JavaScript Variable:

A JavaScript variable is simply a name of storage location.


There are two types of variables in JavaScript
1. Local variable and
2. Global variable.
There are some rules while declaring a JavaScript variable (also
known as identifiers).
1. Name must start with a letter (a to z or A to Z), underscore( _ ), or dollar
( $ ) sign.
2. After first letter we can use digits (0 to 9), for example value1.
3. JavaScript variables are case sensitive, for example x and X are different
variables.
Local variable:
A JavaScript local variable is declared inside block or function.
It is accessible within the function or block only.

<script>
function abc(){
var x=10; // local variable
}
</script>
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.

<script>
var data=200;//gloabal variable
function a(){
document.writeln(data);
}
function b(){
document.writeln(data);
}
a();//calling JavaScript function
b();
</script>
Javascript Data Types:
Data types in JavaScript refers to the types of the values that we are
storing or working with.
One of the most fundamental characteristics of a programming
language is the set of data types it supports.
These are the type of values that can be represented and
manipulated in a programming language.
JavaScript provides different data types to hold different types of
values. There are two types of data types in JavaScript.

1. Primitive data type


2. 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
JavaScript primitive data types:

There are five types of primitive data types in JavaScript


JavaScript String
In JavaScript, the string is a sequence of characters and can be
created using 3 different ways given below
1. Using the single quote
2. Using the double quote
3. Using the backticks
JavaScript Number
A JavaScript number is always stored as a floating-point value
(decimal number).
JavaScript does not make a distinction between integer values
and floating-point values.
JavaScript represents numbers using the 64-bit floating-point
JavaScript Boolean
In JavaScript, the Boolean data type has only two
values: true or false.
JavaScript Undefined
When you declare a variable but don't initialize it, it contains
an undefined value. However, you can manually assign an undefined value
to the variable also.
JavaScript Null
When any variable's value is unknown, you can use the null. It is
good practice to use the null for the empty or unknown value rather than the
undefined one.
JavaScript Bigint
qJavaScript stores only 64-bit long floating point numbers. If you want to
store a very large number, you should use the Bigint.
You can create Bigint by appending n to the end of the number.
JavaScript non-primitive data types
The non-primitive data types are as follows
JavaScript Object
In JavaScript, the object data type allows us to store the collection
of the data in the key-value format. There are multiple ways to define the
object.
Example
In the example below, we used the '{}' (Object literals) to create an
obj object. The object contains the 'animal' property with the string value,
the 'legs' property with the number value, and the value of the 'color'
variable is assigned to the 'hoursexColor' property.
JavaScript Array
In JavaScript, the array is a list of elements of the different data
types.
You can create an array using two square brackets '[]' and insert
multiple comma separated values inside the array.
JavaScript Date
You can use the JavaScript Date object to manipulate the date.
Example
In the example below, we used the Date() constructor to create a
date. In the output, you can see the current date and time according to your
time zone.0
JavaScript Arithmetic Operators
The JavaScript arithmetic operators are used to perform
mathematical calculations such as addition, multiplication, subtraction,
division, etc. on numbers.
JavaScript supports the following arithmetic operators

1. Arithmetic Operators
2. Comparison (Relational) Operators
3. Bitwise Operators
4. Logical Operators
5. Assignment Operators
6. 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 Comparison Operators
The JavaScript comparison operators compare two values and returns
a boolean result (true or false).
JavaScript supports the following comparison operators
JavaScript Bitwise Operators
The JavaScript bitwise operators are used to perform bit-level
operations on integers.
JavaScript supports the following seven types of bitwise operators
JavaScript Logical Operators
The logical operators are generally used to perform logical
operations on boolean values. But logical operators can be applied to values
of any types not only boolean.
JavaScript supports the following logical operators
JavaScript Assignment Operators
In JavaScript, an assignment operator is used to assign a value to a
variable. JavaScript supports the following assignment operators
JavaScript Special Operators
There are few other operators supported by JavaScript. These
operators are conditional operator (? :), type of operator, delete operator,
etc.

You might also like