10 useful js features that you should know.
lets start —
1)Primitve data-
in js , primite data is not an object and has no methods . there are 7 priminte data types.
they are -
string,number,bigint, boolean, undefined,symbol,null,
2)Checking a Type
by using typeof operator ,you can check the types
just like this -
console.log(typeof “am i joke to you?”)
“string”
console.log(typeof false)
console.log(typeof true)
“boolean”
console.log(typeof 1000)
“number”
3) functions with default parameter-
a default argument is a value that is automatically assigned by the computer if we don’t provide a value for the argument with a default value.
here is the example —
function multiply(a, b = 1) { return a * b; }
here ,
in this above code , b=1 is default parameter. if we don’t provide any value for b it will automatically assigne as b=1 that is called default parameter.
4)Arrow Functions-
arrow function is one of the features of es6 . es6 is a version of js. it allows us to create functions in a cleaner way compared to regular functions.
lets see the code ..
//(standard way) var add = function(a,b)
{ return a+ b; }
console.log(add(5,5));
// 10
// Arrow style var add = (a,b) => a+ b;
console.log(add(5,5));
// 10;
5)let and const Variables
The let statement declares a block scope local variable, optionally initializing it to a value.
we can change variable values when we use let
just like this -
let asdf= 1232let asdf=343console.log(asdf)=>343
but, if we use const , we cann’t change variable values.
just do it-
const asdf= 1232const asdf=343console.log(asdf)=>it will showing err.
so, if we need to change the value anytime , than we use let and if we need to declear a specific values that never change , we will use const .
___________that’s for today. thank you