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

JS Data Types, Variables & Operators

This document discusses JavaScript data types, variables, operators, and conditional statements. It describes the primitive data types in JavaScript as numbers, booleans, characters and strings. It also covers non-primitive types like objects. Variables in JavaScript are declared with var and can hold values of any data type. The document defines different types of operators like arithmetic, comparison, logical and assignment operators. It provides examples of if, if-else and if-else if conditional statements in JavaScript.

Uploaded by

Siwani saini
Copyright
© © All Rights Reserved
Available Formats
Download as PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
237 views

JS Data Types, Variables & Operators

This document discusses JavaScript data types, variables, operators, and conditional statements. It describes the primitive data types in JavaScript as numbers, booleans, characters and strings. It also covers non-primitive types like objects. Variables in JavaScript are declared with var and can hold values of any data type. The document defines different types of operators like arithmetic, comparison, logical and assignment operators. It provides examples of if, if-else and if-else if conditional statements in JavaScript.

Uploaded by

Siwani saini
Copyright
© © All Rights Reserved
Available Formats
Download as PDF, TXT or read online on Scribd
You are on page 1/ 27

DATA TYPES, VARIABLES & OPERATORS

Sumit Kumar
JAVASCRIPT DATA TYPES
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 allows you to work with three primitive data
types:
⚫ Numbers (int, float, etc.), e.g., 123, 120.50 etc.
⚫ Boolean, e.g. true or false.
⚫ Char, use to store single char within single quotes, like ‘A’ or
‘c’
JAVASCRIPT DATA TYPES
JavaScript also allows you to work with non-primitive
data types:
Strings of text, e.g. "This text string" etc.
JavaScript also defines two trivial data types, null and
undefined, each of which defines only a single value.
In addition to these data types, JavaScript supports a
composite data type known as object.
JAVASCRIPT VARIABLES
Like many other programming languages, JavaScript has
variables.
Variables can be thought of as named containers.
You can place data into these containers and then refer to
the data simply by naming the container.
In JavaScript, Variables are declared with the var
keyword .
JAVASCRIPT VARIABLES
Storing a value in a variable is called variable initialization.
You can do variable initialization at the time of variable
creation or at a later point in time when you need that variable.
JAVASCRIPT VARIABLES
JavaScript is untyped language.
This means that a JavaScript variable can hold a value of any
data type.
Unlike many other languages, you don't have to tell JavaScript
during variable declaration what type of value the variable will
hold.
The value type of a variable can change during the execution
of a program and JavaScript takes care of it automatically.
JAVASCRIPT VARIABLE SCOPE
Global Variables: A global variable has global scope which
means it can be defined anywhere in your JavaScript code.
Local Variables: A local variable will be visible only within
a function where it is defined. Function parameters are
always local to that function.
JAVASCRIPT VARIABLE SCOPE
Within the body of a function, a local variable takes
precedence over a global variable with the same name.
If you declare a local variable or function parameter with the
same name as a global variable, you effectively hide the
global variable.
JAVASCRIPT RESERVED WORDS
WHAT IS AN OPERATOR?
Let us take a simple expression 4 + 5 is equal to 9. Here
4 and 5 are called operands and ‘+’ is called the operator.
JavaScript supports the following types of operators.
⚫ Arithmetic Operators
⚫ Comparison Operators
⚫ Logical (or Relational) Operators
⚫ Assignment Operators
⚫ Conditional (or ternary) Operators
ARITHMETIC OPERATORS

S. No. Operator and Description


1 + (Addition)
2 - (Subtraction)
3 * (Multiplication)
4 / (Division)
5 % (Modulus)
6 ++ (Increment)
7 -- (Decrement)
EXAMPLE
COMPARISON OPERATORS

S.No Operator and Description


1 == (Equal)
2 != (Not Equal)
3 > (Greater than)
4 < (Less than)
5 >= (Greater than or Equal to)
6 <= (Less than or Equal to)
EXAMPLE
LOGICAL OPERATORS

S.No Operator and Description


1 && (Logical AND)
2 || (Logical OR)
3 ! (Logical NOT)
EXAMPLE
ASSIGNMENT OPERATORS

S. No Operator and Description


1 = (Simple Assignment )
2 += (Add and Assignment)
3 -= (Subtract and Assignment)
4 *= (Multiply and Assignment)
5 /= (Divide and Assignment)
6 %= (Modules and Assignment)
EXAMPLE
MISCELLANEOUS OPERATORS

Sr. No Operator and Description


1 ? : (Conditional )
EXAMPLE
IF-ELSE
JavaScript supports the following forms of if..else
statement:
⚫ if statement
⚫ if...else statement
⚫ if...else if... statement
IF STATEMENT
EXAMPLE
IF...ELSE STATEMENT
EXAMPLE
IF...ELSE IF... STATEMENT
EXAMPLE

You might also like