Some Important core concepts of JavaScript.
Let’s discuss some core concepts of Javascript.
Numbers
There are few types of numbers. Integer, Float, etc. An integer is a number that has no fractional number and float has a fractional number.
Here is an example:
let myNumber = 43; // it is an integer
let myNumber = 43.56; //it is a float number
Some number method:
- Math.round()
it is used for making a number as an integer value.
example:
let myNumber = 66.76;
Math.round(myNumber); // 67
let myNumber = 66.46;
Math.round(myNumber); // 66
if the fraction value is grater than .5 then the method increase the number and remove fraction otherwise only remove fraction.
2. Math.ceil()
this method used for making number round but it every time increase 1 and remove fraction from the number.
3. Math.floor()
this method used for making number round but it every time remove fraction from the number no increase happen here.
4. Math.random()
it is a very useful method. if you need some random value you just call the method and it will create a random value.
Strings
Strings mean Unicode characters.
Here is an example:
let myName = “alamin” // it is an string
the number can be a string if “” sign used in a number like that “54”
Some string method:
- charAt()
it is a string method that provides a character with its index.
example:
const name = “Jhankar Mahbub”;
const result = name.charAt(3);
console.log(result); // n
2. toUppercase()
it is used to make whole string uppercase letters.
example:
const name = “Jhankar Mahbub”;
const result = name.toUppercase();
console.log(result); // JHANKAR MAHBUB
3 toLowercase()
this method makes string to lowercase letter.
example:
const name = “Jhankar Mahbub”;
const result = name.toLowercase();
console.log(result); // jhankar mahbub
Arrays
An array is an important data type of javascript. [] used for making an array. it is one kind of object.
const color = [‘red’,’blue’,’green’];
this is an array which name is color.
Some array method:
- push()
this method is used for adding a new element into the array.
example:
const color = [‘red’,’blue’,’green’];
color.push(‘white’);
console.log(color); // [‘red’,’blue’,’green’,’white’]
2. pop()
this method used for remove an element from array.
example:
const color = [‘red’,’blue’,’green’];
color.pop();
console.log(color); // [‘red’,’blue’];
3. indexOf()
this method used to find an element with an index number.
example:
const color = [‘red’,’blue’,’green’];
color.indexOf(1); // blue
That's for today.