Saturday, September 13, 2014

Variables , comments & Operators

Hello friends   Our in this tutorial we are going to learn about the variables & Operators

What is variables ?

As we Learn from other programming languages the variables are the containers to contain the value or we can say variables are memory buckets which we can use in our program. They stores the Information. Variables name is shots name to contains the values from other sources 

variables name contains the letters , digits, underscores , and dollar signs 

Points to be Remembers while declaring variables names :
  • Must begins with a Letter
  • Can also begins with $ and _ 
  • Variable name never Start with number
  • Variable names are case sensitive
  • Reserve words can't be used as variable names like ( JavaScript )
Note :: JavaScript Statements and JavaScript variables both are case-sensitive

How to Declare a Variable in JavaScript :

var, keyword var is used to declare a variable in the JavaScript as we declare the variable then it is like a empty bucket Now we also need to feel this bucket too so to do this we use = equal to sign equal to sign assign the value to the variable Let's understand this all process that how we can create a variable & how to store the value in it & how we can call it in our html program


in the above image you can see here i tried to show you single variable declaration & also the multiple variable declaration which i comment out here also try to show you the comments for multiline   


Open it in the web Browser & you can see variables which is declared is printed on the screen as Lenovo & next we have a list of array & we want to print one from the List Let's see how it works after all we try to make it more Interesting by other methods so let's start with it


Here in the image i tried to show about the single comments & also shows how to define multiple values to the same variables

so in the output you can see the value of the variable i call with document.write method here 

Key Point to Remembers about variables in JavaScript
  •  If you are dealing with multiple variable then try to define in Different lines , 
  • There is no effect if we declare one variable twice it's name remains the same 
  • But if you assign values then it accept the 2nd variable 



Comments in JavaScript :

JavaScript with modern Browser accept single Line comment as //
Multiline comments are <-- values comment outs  //-->
& in Multiline comments one more type as 
/* 
Line one 
Line Two
Line Three 
Line Four
*/

Operators in JavaScript :

as other programming languages JavaScript support various Types of Operators these are Given Bellow
--------------------------------------------------------------------------------------------
+ Adds two no or appends two strings-if more than one type of variable is appended, including a string appended to a number or vice-versa, Result will be string.
--------------------------------------------------------------------------------------------
- Subtracting the second from first
--------------------------------------------------------------------------------------------
/ Divide the first no by the second
--------------------------------------------------------------------------------------------
* Multiply two nos.
--------------------------------------------------------------------------------------------
% Divide the first no by second and returns the remender
--------------------------------------------------------------------------------------------
= assign the values to the right to the object on the left
--------------------------------------------------------------------------------------------
+= The object on the left = the object on the left + the value on the right - also works when appending strings
--------------------------------------------------------------------------------------------
-= The object on the left = the object on the left - value on the right
--------------------------------------------------------------------------------------------
> number on the left = the object on the left - The value on the right
--------------------------------------------------------------------------------------------
< number on the left must be less than or equal to the number on the right - also works with strings
--------------------------------------------------------------------------------------------
>= number in the left must be grater than or equal to the no on the right- this also works with string and values
--------------------------------------------------------------------------------------------
<= number on the left must be less than or equal to the number on the right - also works with strings and values
--------------------------------------------------------------------------------------------
++ increment the numbers
--------------------------------------------------------------------------------------------
-- Decrements the numbers
--------------------------------------------------------------------------------------------
== The numbers or objects or values must be equal to
--------------------------------------------------------------------------------------------
!= The numbers or objects or values must not be equal to
--------------------------------------------------------------------------------------------
<< Bitwise Leftsift
--------------------------------------------------------------------------------------------
>> Bitwise Rightsift
--------------------------------------------------------------------------------------------
& Bitwise AND
--------------------------------------------------------------------------------------------
| Bitwise OR
--------------------------------------------------------------------------------------------
^ Bitwise XOR
--------------------------------------------------------------------------------------------
~ Bitwise NOT
--------------------------------------------------------------------------------------------
! logical NOT (statement must not be true)
--------------------------------------------------------------------------------------------
&& Logical AND (Both statement must be true)
--------------------------------------------------------------------------------------------
|| Logical OR (either statement must be true )
--------------------------------------------------------------------------------------------
in Object or array on the right must have the property or cell on the left
--------------------------------------------------------------------------------------------
=== The numbers or objects or values must be equal, and must be the same variable type
--------------------------------------------------------------------------------------------
!== The numbers or objects or values must not be equal, or must not be the same variable type
--------------------------------------------------------------------------------------------
Share this post

0 comments

:) :-) :)) =)) :( :-( :(( :d :-d @-) :p :o :>) (o) [-( :-? (p) :-s (m) 8-) :-t :-b b-( :-# =p~ :-$ (b) (f) x-) (k) (h) (c) cheer

© 2017 Friends Code
Designed by cyb3r.gladiat0r
Posts RSSComments RSS
Back to top
Hack for India, Code for India, Configuration for India, Die for India !