Friday, May 26, 2017

Java Script Data Type

 💥JavaScript variables can hold many data types: 

  • numbers 
var length = 16;
  • strings
 var lastName = "Johnson";    
  • objects  
 var x = {firstName:"John", lastName:"Doe"};
  • boolean
<script>
document.getElementById("demo").innerHTML =
typeof true + "<br>" +
typeof false;
</script>

  • null
 <script>
var person = {firstName:"John", lastName:"Doe", age:50, eyeColor:"blue"};
var person = null;
document.getElementById("demo").innerHTML = typeof person;
</script>


out put object

  • undefined 
 <script>
var person;
document.getElementById("demo").innerHTML =
person + "<br>" + typeof person;
</script>
 
  💥JavaScript evaluates expressions from left to right. Different sequences can produce different results


  👊<script>
var x = "Volvo" + 16 + 4;
document.getElementById("demo").innerHTML = x;
</script>



 output  volvo164


 👊 <script>
var x = 16 + 4 + "Volvo";
document.getElementById("demo").innerHTML = x;
</script>


output 20Volvo

  💥We can use single or double invert comma  for string &  use quotes inside a string
 
 👊<script>
var carName1 = "Volvo XC60";
var carName2 = 'Volvo XC60';
var answer1 = "It's alright";
var answer2 = "He is called 'Johnny'";
var answer3 = 'He is called "Johnny"';

document.getElementById("demo").innerHTML =
carName1 + "<br>" +
carName2 + "<br>" +
answer1 + "<br>" +
answer2 + "<br>" +
answer3;
</script>


output  

Volvo XC60
Volvo XC60
It's alright
He is called 'Johnny'
He is called "Johnny"

             

No comments:

Post a Comment