3 min readFrontend
Basics In JavaScript
Javascript is a widely-used programming language. Some of us learning this language or some of as already mastered this language. But someone who just started the journey of this…
- JavaScript

Javascript is a widely-used programming language. Some of us learning this language or some of as already mastered this language. But someone who just started the journey of this language. Must have to know the building blocks of JavaScript.In this article, I will show you some of the basics in javaScript.
JavaScript has 2 kinds of the data type. Those are
- Primitive Data Type.
- Non-primitive Data Type.
Primitive Data Type
In primitive data type, you can store data directly. Those primitive data types are :
- Number.
Any kind of number is a number data type.
2. String.
A string stores a series of characters like “I have a car”. A string can be any text inside double or single quotes.
3. Boolean.
Boolean has two value. Those are: true or false.
4. Undefined.
When you declare a variable, but you didn’t assign a value. That the variable default value is undefined.
let myName;
console.log(myName); // result is undefined.5. Null.
It does not exist in any corner.but not undefined either. That means you don’t want to put anything in your variable, but again you don’t want to keep it undefined either.
let yourName = null;
console.log(yourName); // result is null.
console.log(typeof yourName); // The type of this value is null.Non-primitive Data Type
In the non-primitive data type, you can’t store data directly. Those primitive data types are :
- Array
The Array object lets you store multiple values in a single variable. It stores a collection of elements of the same type.
let friendsName = ['kobir', 'fokir', 'chokir']2. Object.
Everything In JavaScript is an object except primitive data. An object is a collection of properties, and a property is an association between a name (or key) and a value.
const student = {
name : "Tokir",
roll: 12,
subject : ["English","Math","Science"]
}3. Function.
The function is a set of method that performs a task. A function can take 0 or more parameters. Parameters guide a function to performs a task.
function sumNum (a) {
const b = 4;
return a+b
}
sumNum (5); // The funtion will return 9.Let’s me demonstrated some common methods in Javascript.
Character Access
If you want to access a character from a string. You can do it by using charAt() method. To access a character, you have to provide the index number of that character as a parameter.
const myName = "shakib";
console.log(myName.charAt(3)) // The result is k.Concatenates the string
To concatenate two string using the concat() method. The concat() method concatenates the string arguments to the calling strings and returns a new string.
const string1 = "Hello";
const string2 = "World";
const newString = string1.concat(" ", string2);
console.log(newString); // The value of newString is "Hello World".Trim the white space
The trim() method removes whitespace from both ends of a string.
const name = " shakib ";
console.log(name.trim());
// Result is shakib. It remove all the whitespace.Math.ceil()
The Math.ceil() function always rounds a number up to the next largest integer.
console.log(Math.ceil(4.56)); // Output is 5.
console.log(Math.ceil(-4.56)); // Output is 4.Math.max() and Math.min
Math.min() method returns the highest number passed into it, or NaN if any parameter is not a number and can not be converted into one. On the other hand Math.min() method returns the lowest number or NaN if any parameter is not a number and can not be converted into one.
const number = [4,1,8,2];
console.log(Math.max(...number)) // The output is 8.
console.log(Math.min(...number)) // The output is 1.
console.log(Math.min()) // The output is NaN.There are more methods and basics you will find in MDN (opens in a new tab).
Originally published on Medium (opens in a new tab).