You are currently viewing Variables, DataTypes, Objects in JavaScript. JS Crash Course.

Variables, DataTypes, Objects in JavaScript. JS Crash Course.

  • Post category:Coding / Software
  • Reading time:4 mins read

Why Learn JavaScript in 2020-21?

  • It is currently used by 94% of the websites you see on the World Wide Web(www).
  • It is super easy for the newbies to grasp the language structure and use it for their logic or code.
  • JavaScript is one of the core technologies that is powering the whole internet today.
  • JavaScript is having a very large community all around the globe. You can easily find all the error fixes and solutions.


Defining Variables in JavaScript:

<!DOCTYPE html>
  <title>getElementById method</title>
  <p id="para">Final Result is: </p>
  <button onclick="Result();">Result</button>

function Result(){
  var x,y,z,res;
  y="This is a String";
 var element= document.getElementById("para");
  element.innerHTML= res;

In JS automatic type casting for a variable takes place. This means if the data is Integer than the var type is ‘int’ or if the data is String than the var is ‘string’ or if the data is decimal then the JS will automatically typecast the variable to ‘float or double’.

Changing inner HTML using Document method getElementById():

In this program what we did is that first we created the basic HTML form using buttons and paragraph text and using that we parse the Colors from our HTML form to the JavaScript Function and from there we changed the inner HTML content using the value passed to the function on different button calls. Hence this resulted in an immediate change in the text and color of our program.

Using different Data Types in JavaScript:

var x,y;
x='My name is Tom and I am ';
z=x+y+" years old";

var LargeNum, SmallNum;

When we try to add a number with a string or vice versa JavaScript treats the final result as a ‘String’. You can use single or double quotes for string it doesn’t matter at all.

For denoting extremely large scientific or numerical values exponential format can be used which involves the ‘e’ character after the int value for denoting its power(i.e Negative or Positive).

Arrays In Java Script:

var mobile_brands=["Apple","Motorola","Samsung","Xiaomi"];

In JS arrays are defined with Square Brackets with values separated with commas. Arrays are homogenous means we can store all types of values inside the same Array type variable. For accessing the values each value is assigned an Index Value using which we can easily access the data.

Objects in JavaScript:

var customer={Name:"Rob Percievel", Id:"237DA", Product:"Car", Price:"$30,000"};

JS Objects are structured in Curly Braces with some property or attribute values referring to the object itself. The properties of the objects are separated by commas.

Undefined and Empty values:

var name="Alex";   //string type
var class;         // type is undefined
var name=undefined; //name given type undefined
var class="";       //type is string but empty

NULL(biggest error in JS):

var customer={Name:"Rob Percievel", Id:"237DA", Product:"Car", Price:"$30,000"};

The type of null in JavaScript is an object and this is a very big mistake because the type of null should be null but isn’t and therefore causes confusion. Any object could be defined as empty by just setting the value to null.

The type of null in JavaScript is ‘object’ and that of undefined is ‘undefined’, but still null is equal to undefined. Both of them can be used to make an object empty.

Please refer to other articles on our website for complete content. Thank You So Much for your support.

Share with others:)

This Post Has 6 Comments

  1. bursa escort

    Thanks for this message. It reminded me of how a healing can come to pass. Maryl Massimo Urbanus

  2. erotik

    Major thankies for the article post. Thanks Again. Really Cool. Auguste Shurwood Carling

  3. Supertotobet

    This comment has been removed by a blog administrator. Sorcha Pacorro Magdalen

  4. Wilbur

    Genuinely when someone doesn’t be aware of after that its up to other
    people that they will help, so here it occurs.

Leave a Reply