DEV Community

Vignesh . M
Vignesh . M

Posted on

JAVASCRIPT CL-3

Day 3

*Javascript is a dynamic type- if meation the type means is realted to the datatype

In javascript
let i= 10;
i= "abc";
i= null;
In javascript will reassin the value number to string -number to boolean this is call dainamic typing


     let i = 10;
        console.log(i);
        i= "abc";
        console.log(i);
        //output - 10  abc
Enter fullscreen mode Exit fullscreen mode
    //find the type using type of
Enter fullscreen mode Exit fullscreen mode
 let j = 10;
        console.log(typeof j);
        j= "abd";
        console.log(typeof j);
        //output : number  - string
Enter fullscreen mode Exit fullscreen mode
//function is a keyword 
Enter fullscreen mode Exit fullscreen mode

//function is a set of instruction with a name
//// the mainthing to use to create the function to use the code reuseablity if need the set of code need will call only the fuctionname only .
syntax of createing funtion


    function functionName()
    {

    } 

Enter fullscreen mode Exit fullscreen mode

sample code :

function functionName()
    {
        console.log("hi function");

    } 
    functionName();// this a function calling statement

Enter fullscreen mode Exit fullscreen mode

if call the function calling multiple times if you needed
////function - is keyword : functionname - is a nameof the function : () - need input inside the ()

 function add(no1,no2)
    {
        console.log(no1+no2);
    }
    add(10,20);//output : 30
    add(20,48);//output : 68
Enter fullscreen mode Exit fullscreen mode
//sample code 2
Enter fullscreen mode Exit fullscreen mode
function greeting(name)
    {
        console.log("hii goodmoring " +name);
    }
    greeting("vicky")//output: hii goodmoring vicky

Enter fullscreen mode Exit fullscreen mode

**_//function is call hoisted

  • Function Declarations: Function declarations are fully hoisted, meaning both the declaration and the function's definition are moved to the top of their scope. This allows functions to be called before they are declared in the code

    //variavle is call not-hoisted _**

 let k=10;
    console.log(k);//output : 10
Enter fullscreen mode Exit fullscreen mode

//task 1
//fuction (''abc") find the type of variable in the output

 function tasks(name)
    {
        console.log(name + typeof name);
    }
    tasks("kumar");
    tasks(152)
    tasks(1657746365n)

output:
    kumarstring 
    152number
    1657746365bigint 

Enter fullscreen mode Exit fullscreen mode

Top comments (0)