Interview Questions & Answers

javascript

  • Its a mechanism where variables and functions declaration to the top of the scope.

  • It’s a mechanism where variables and function declaration are moved to the top of the scope.

  • Null :- We assign value NULL, it indicates absence of data.
  • Undefined :-  Variable has been created but value is not assigned.

  • Null indicates intentional absence of data. Null indicates its not ZERO, its not empty its just absence of data.
  • <script>
      var y = 10;
      var z = “Shiv”;
      var x;
      var emptystring = “”;
      var zero = 0;
      var n = null;
    </script>

  • Undefined means the variable has been declared but no value is assigned to it.
  • Example:-
<Script>
  var y = 10;
  var z = “Shiv”;
  var x;
</Script>
So here “var x” is Undefined

  • There are 8 types of data type. And it is divided into two parts.
  • 1.Primitive 2.Objects
  • Primitive – string, number, null, undefined, boole, big int, symbol.
  • Objects – object.

  • JavaScripts determines data types depending on the value assigned.

<Script>

var x=100;

var watisdatatype = typeof(x);

x=true;

waitsdatatype = typeof(x);

<Script>

  • JavaScript is a dynamic language means data types of the variables can change during the run time.

<script>

var x=0;

x++;

x = “Text1”;

x = true;

</script>