JavaScript Data Types

  

JavaScript is a single-threaded language 

JavaScript is a single-threaded language because while running code on a single thread, it can be really easy to implement as we don't have to deal with the complicated scenarios that arise in the multi-threaded environment like a deadlock. 
Since JavaScript is a single-threaded language, it is synchronous in nature

What does mean by declaration- assignment- initialization !! in java script ?? Initialization: When you declare a variable it is automatically initialized, which means memory is allocated for the variable by the JavaScript engine.

Assignment: This is when a specific value is assigned to the variable.

And Hoisting available only for declaration , its not available for assignment and initialization.

     
        // Hoisting in JavaScript

        // debugger;
        // console.log(a,b,c);
        // d();
        // e();

        var a = "A";
        let b = "B";
        const c ="C";
        function d(){
            console.log("D");
        }
        var e = function(){
            console.log("E");
        }

        console.log(a,b,c);
        d();
        e(); Scope in Variables :: let , Var , Const .
JavaScript variables can hold different data types: numbers, strings, objects and more:

they are ..

var x = "Hellow World";                        // String
var
 x = 
25;                                    // Number
var x = true ;                                 // Boolean
var x = ["HTML","CSS","JS"] ;                  // Array
var x = {firstName:"John", lastName:"Doe"};    // Object
var x = null ;                                 // Null
var x                                        // Undefined

Meaning  of DataTypes =
Different types of variable value is a data types, they are..

JavaScript Strings

A string (or a text string) is a series of characters like "John Doe". Strings are written with quotes. You can use single or double quotes:

let carName1 = "Volvo XC60";   // Using double quotes
let carName2 = 'Volvo XC60';   // Using single quotes

document.write(carName1);


JavaScript Numbers

JavaScript has only one type of numbers.
Numbers can be written with, or without decimals:


let x1 = 34.00;     // Written with decimals
let x2 = 34;        // Written without decimals

document.write(x1);


JavaScript Arrays

JavaScript arrays are written with square brackets. Array items are separated by commas. The following code declares (creates) an array called cars, containing three items (car names):

const cars = ["Saab""Volvo""BMW"];
document.write(cars);

array with index

var ary = [10,20,30,40,50];
document.write(ary[2]);

array with for loop..

var ary = [10,20,30,40,50];
for (var a = 0; a <= 4; a++){
    document.write(ary[a]+"<br>");
 }      

nested array 


<script>  

var user =["ramesh", 22, "pune", ["Male",25000]];

var [name, age = 20, city , [gender, salary]] = user;

console.log(name);
console.log(age);
console.log(city);
console.log(gender);
console.log(salary);

</script>

array with function..

<script>  

  function user([name,age=20, city]){
    console.log(name);
    console.log(age);
    console.log(city);
  }

  user(["code guruva",22, "Delhi"]);

</script> 
       
     

JavaScript Objects

JavaScript objects are written with curly braces {}.
Object properties are written as name:value pairs, separated by commas.

               
        var a = {
            fname : 'product',
            lname : "one",
            age : 25,
            email : 'ramesh@gmail.com',
        }

        // document.write(a);
        // console.log(a);

        console.log(a.email);
       
Destructing Objects
               
       var user ={
        name:"ramesh",
        age:"29",
        city:"banglore"
       }

       var {name, age, city} = user;

       console.log(name);
       console.log(age);
       console.log(city);


    <script>

        var n = "student";
        var obj ={
            [n + "name"] : "Ram Babu",
            course : "MTech",
            detail : function(){
                return `${this.studentname} is student of ${this.course}`
            }
        };
        console.log(obj);
        console.log(obj.detail());

    </script>

       


Undefined

In JavaScript, a variable without a value, has the value undefined. The type is also undefined. Any variable can be emptied, by setting the value to undefined. The type will also be undefined.

let car;    // Value is undefined, type is undefined
car = undefined;    // Value is undefined, type is undefined

Empty Values

An empty value has nothing to do with undefined.An empty string has both a legal value and a type.

let car = "";    // The value is "", the typeof is "string"

Ex : 

        // undefined variable value
        var abc ;
        console.log(abc)

        // undefined function value
        function msg(y){
            console.log(y)
        }

        msg();

Null Value :

        // null value with variable
        var abc = null ;
        console.log(abc);

        // null value with variable object
        var student ={
            sname:"kishore",
            course:null
        }

        console.log(student.course);


JavaScript Booleans

Booleans can only have two values: true or falseBooleans are often used in conditional testing.

let x = 5;
let y = 5;
let z = 6;
(x == y)       // Returns true
(x == z)       // Returns false


Ex :

        //variable with boolean
       
        var abc = 0;
        var msg = 1;

        var value = Boolean(abc);
        document.write(value);