10 Basic topics of JavaScript
Hey Guys ! 👋
This is Daiyan back again and today I’ll gonna show you the very very basics of JavaScript. SO, if you’re excited jump with me 😉
Let’s Get Started !
String
String is like, if you wrap some characters between a quotation mark it will be a string in JavaScript. So, A string is made up of a number of characters.
Example:
const string = "This is a string in JavaScript !"
Now, string has many methods that made our life easy…Some useful methods are :-
chartAt, length, toUpperCase, toLowerCase, includes, replace etc.
Boolean
Boolean is all about conditions….There are 2 values are boolean values. True and False.It is commonly used in if else conditions.
For Example:
const jsLibrary = "react"
if(jsLibrary === "react") console.log(true)
else console.log(false)
Number
JavaScript has two types of Number:
- Integer
- Float
Integer: Integer is not decimal values are integer. Like 45, 1874, 21
Float: Might be you guessed that what is Float ? Yes ! Decimal Values are float. Like 25.54, 78.3
There are MIN_VALUE and MAX_VALUE in JavaScript. MIN_VALUE in JavaScript is 5e-324. This is the smallest possible number in JavaScript, MAX_VALUE is 1.7976931348623157e+308. This is the largest possible number in JavaScript.
There are some methods for Numbers. Like :-
parseInt, parseFloat, toFixed, toString etc.
Array
Array is a Data Structure where we can store data's. We can store any data types in an array
Example:
const arr = ['apple', 'banana', 'pineapple', 'mango']
There are some methods which are very useful and makes our life so easy. Like forEach, map, filter, find, reduce, push, pop etc.
Object
Object is used to store some information about anything. Such as, we can store a student’s information in an object.
Example:
const student = {
name: 'Anas',
age: 12,
grade: 7
}
Function
Function is a code block which designed to perform a particular task.If we call a function, It will be executed.
function add(num1, num2) {
return num1 + num2;
}
Null & Undefined
Null represents empty value of an object. It is a falsy value in JavaScript. The difference between null and undefined is undefined is variable is declared but not assigned. Null is assigned but no value.
// Null
const student = {
name: 'Anas',
age: 12,
grade: 7
id: null
}
if(student.id === null) {
return 0
}// Undefined
let notAssigned;
console.log(notAssigned) // undefined
Math
Math is an object to perform mathematical operations in JavaScript. It is very helpful for doing mathematical tasks. So that, we don’t need any libraries even.
There are many methods of math like random, floor, ceil, round, PI, pow.
console.log(Math.floor(5.95)); // 5
Condition
Conditions are used to perform task based on different conditions. We use if-else statement to make conditional tasks.
const num = 12;
if(num === 10){
console.log('true')
} else {
console.log('false')
}
So, That’s it for Today :) Next Day we will discuss more about JavaScript. Until then, Code and sleep 👩💻😴👩💻😴