JS Data Types, Variables & Operators
JS 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