Things you need to know about javascript.

Faisal Ahmed
4 min readMay 5, 2021

--

JavaScript is a scripting language that allows users to implement complex features on web pages. The popularity of javascript is growing day by day. Today we are gonna learn some important topic about javascript.

null

When we expect a value but we didn’t know that value then we assign a value as a placeholder which is called null. Null is a data type that is javascript that represents the absence of value or the unknown value. Null is explicitly set by the developer. Null is used when some value is unknown and the value will set by the user. The null is falsy for the boolean operator.

let a= null;
console.log(a);

output = null

here the value of variable a is null. Because we expect a value from the user.

undefined

In javascript when we declare a variable by didn’t assign any value so by default the value assigned is the variable is called undefined.

let a;
console.log(a);

output = undefined

here no value is inserted for the variable a. So that the output is undefined.

It is in a function we didn’t explicitly return anything then the output will be undefined.

function add(num1,num2){
console.log(num1+num2};
const result =add (13,82);
console.log(result);
output = 95
output = undefined

String.prototype.slice()

the slice() method is a method in javascript that removes a section from a string and it returns the removed section as a new string and doesn’t modify the original string.

const str = 'The Sun is the star at the center of the Solar System ';
console.log(str.slice(11));
// output: "the star at the center of the Solar System "console.log(str.slice(4, 19));// output: "Sun is the star"

in the first example, we see in because slice()method we get a new value which starts from position 11, and in the second example, the new value starts from position 4 and ends and 19.

string.prototype.indexOf()

the indexOf() method finds the exact index of a particular string. The index number starts with zero. It returns -1 if the value is not found.

const sun =  'The Sun is the star at the center of the Solar System ';
const search = 'Sun';
const indexOfSun = sun.indexOf(search);
console.log(`There is the index of the "${search}" from the starting ${indexOfSun}`);// output: "There is the index of the "Sun" from the starting 4 "

there we see is the index of the sun is at position 4.

String.prototype.toLowerCase()

the toLowerCase() method converts the string input into lower case .toLowercase() used when a character needs to show is lower case letter.

const hello=”The Moon is Earth’s only natural satellite.”;console.log(hello.toLowerCase());
//output:"the moon is earth's only natural satellite."

here from the example, we can use the hello variable contains the same and capital letter. But after the employment of toLowerCase() there is no capital letter. All letters became small letters or lowercase letters.

String.prototype.toUpperCase()

the toUpperCase() method converts the string input into lower case .toUpperCase() used when a character needs to show is upper case letter.

const hello=”The Moon is Earth’s only natural satellite.”;console.log(hello.toUpperCase());
//output:"THE MOON IS EARTH'S ONLY NATURAL SATELLITE."

here from the example, we can use the hello variable contains the same and capital letter. But after the employment of toUpperCase() there is no capital letter. All letters became capital letters or uppercase letters.

Number.parseInt()

parseInt() convert a float number into a integer. also, if any number is located into a string parserInt will find the number and then convert it into an integer number and show output in

let num1 =2;let num2=15.2;let num3='15';num2=parseInt(num2);num3=parseInt(num3);console.log(num1+num2+num3);// output= 32

from the example, the num1 variable holds an integer type number, the num2 variable holds a float type variable, and num3 holds a string type number.parseInt() convert the value of num2 and num3 into integer type and give the output into integer type number.

Number.parse float()

parse float() convert an integer number into an integer. also, if any number is located into a string parserInt will find the number and then convert it into an integer number.

let num2=15.2;let num3='15';num2=parseFloat(num2);num3=parseFloat(num3);console.log(num2+num3);

from the example, we can see parseFloat convert the value of variable num3 and give output as a float number.

Math.max()

math.max() method returns the largest number given as input parameter.

let num1=500;let num2=700;let num3=600;let max=Math.max(num1,num2,num3);console.log(max);//output =700

there is three variable contains three different number. Using the Math.max() we can find the largest number.

Math.min()

math.min() method returns the smallest number given as input parameter. If the parameter isn’t a number it will return null.

let num1=500;let num2=700;let num3=600;let min=Math.min(num1,num2,num3);console.log(min);//output =500

there is three variable contains three different number. Using the Math.min() we can find the smallest number. If the parameter isn’t a number it will return null.

Array.prototype.find()

find() method searches in the array and return one item based on the provided test. If it doesn’t find anything it will return undefined.

const elements = [50, 122, 38, 30, 4];
const findElement = elements.find(element => element > 100);
console.log(findElement);
// expected output: 122

Here we can see there are five elements in any array called elements. Use the find()method we try to find which element is larger than 100. find() method return output 122 which is larger than 100.

These are some important topics on javascript, I hope you find them useful. Thank you for reading.

--

--