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
//find the type using type of
let j = 10;
console.log(typeof j);
j= "abd";
console.log(typeof j);
//output : number - string
//function is a keyword
//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()
{
}
sample code :
function functionName()
{
console.log("hi function");
}
functionName();// this a function calling statement
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
//sample code 2
function greeting(name)
{
console.log("hii goodmoring " +name);
}
greeting("vicky")//output: hii goodmoring vicky
**_//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
//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
Top comments (0)