JAVA SCRIPT VARIABLE AND DATATYPE.

What is Variable ?

Variable is just like a container which store the value into it .
ex- var x=6;
let y=x+z;

In above example x and y is a variable which store some value in it.
The variable is declare with var , let keyword.

In JavaScript we use var keyword for declaring the variable. var is use to specify the datatype of the value,It can hold any type of value such as numeric , string etc;

ex- var name =”Subham ,Karan, Musahid “; // in this variable we store string value inside name variable.
var Mob_no =1000100; //in this we store numeric value inside this variable.

Types of Variable.

There are two types of variables :-

1- Global variable

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

EX:- global variable

<script>  
var value=50;    //global variable  
function a()
{  
alert(value);  
}  
function b()
{  
alert(value);  
}  
</script> 

2- Local variable

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

EX:- Local variable

<script>  
function abc()
{  
var x=10;    //local variable  
}  
</script>

Datatype In JavaScript.

JavaScript provides two type of datatype for storing variable..

  1. Primitive Datatype
    1. String :- For storing sequence of the character.
    2. Number :- To represent numeric value in the variable.
    3. Boolean :- Store one value either true or false.
    4. Undefined :- Represent undefine variable.
    5. Null :- Store null value only.
  2. Non-Primitive Datatype
    1. Object :- Represents instance through which we can access members.
    2. Array :- Store collection of similar datatype.

Thanku

Related Posts

JavaScript Intro And Basic

JavaScript JS is a part of web page that’s defines all the action perform on the web pages. JS is a programming language with oop concepts. JS…

Read More

jQuery Basic

jQuery is a JavaScript library. The purpose of jQuery is to make it much easier to use JavaScript on the website. jQuery syntax is tailor made for…

Read More

PHP | Data Types

In PHP, Data types are used to declare one particular type of data as in all programming languages. Data Types define the type of data a variable…

Read More

Why PHP Is Still So Important for Web Development?

PHP (Hypertext Preprocessor) is a general-purpose scripting language that can be used to develop dynamic websites. It was from the first server-side languages that could be embedded…

Read More

What is Loops in JavaScript?

Looping in programming languages is a feature which facilitates the execution of a set of instructions/functions repeatedly while some condition evaluates to true. For example, suppose we…

Read More

What is JavaScript?

JavaScript is a scripting or programming language that allows you to implement complex features on web pages every time a web page does more than just sit…

Read More