JavaScript 0 to 10

A Girl From Bangladesh
5 min readMay 17, 2021

JavaScript the language was created by an Engineer of Netscape named Brendan Eric in 1995. This language was first released with Netscape 2 in early 1996 and the recent 6th edition was released in June 2015.

Javascript syntax is based on Java and C language and it is seen that many structures from Java and C are used in JavaScript.JavaScript Supports object Oriented Programming. It is more likely to use Functional programming in JavaScript where a function is stored as a variable and pass as an object.

Now moving to the JavaScript Types. Hope you already heard about JavaScript's various Types named Number, String, Math, Boolean, Function, Object, etc. here I will try to discuss the most commonly used 10 topics(types) of JavaScript.

String: If you are using or intend to use JavaScript language you must know about numbers and strings first. Simply, a string is named to the data which is represented in text format.

There are two ways to implement a string. first way is string primitives using string literals. that means just directly write the text inside double or single quotes.

const string1='this is string primitives'`

The second way is string objects. this is nothing but just using string() constructor.

const string2=new String('this is string object')`

You will find so many methods for string like-charAt, concat, includes, endsWith, indexOf, lastIndexOf, replace, slice, split, startsWith, substr, toLowercase, toUppercase, trim, trimStart, trimEnd, and so on.

Numbers: JavaScript use numbers for mathematical operations. constructor Number() creates a new number value.Like as string Numbers also have many methods. Abs, ceil, floor, min, max, random, round, sqrt, etc.

Boolean: JavaScript Boolean represents two values. 1. True & 2. False.

numerically 1 represents true value and 0 represents the false value.

(10>9) // returns true;

(9>10) // returns false;

Function: Function is the most important and you can say fundamental (if you are really building an interactive code) topic of JavaScript.You define your action for the task with the help of a defined function. How your code will actually work will be defined within your functions.

Basically, you will find Two types of functions.

  1. Named Function: function will have a name. will be called by nameOfTheFunction()
`function namedFunction(arguments){
//do something
}
Example: function add(a,b){
var sum = a+b;
return sum;}
add(3,5) // 8

2. Anonymous Function: function necessarily doesn't need a name.

var variableName=function(arguments){
//do something
Example: var add= function(a,b){
return a+b
}
add(3,5) // 8

Another type of function is Recursive. A recursive function is a function that calls itself during its execution.

function factorial(n){
if(n == 0){
return 1;
}
else{
return n* factorial(n-1)
}
}
var result=factorial(10);
console.log(result) //3628800

Object: Objects are basically a collection of values or data inside the second bracket {}. these data will be represented with a property associated with a name (key) and a relevant value.

var object1={
name:'Ahmed',
age:31,
country:'Bangladesh',
occupation:'business',
}

here name, age, country, occupation are the property name, so it's key to that object1. ‘Ahmed’, 31, ‘Bangladesh’, ‘Business’ are the value to those keys.

Arrays: Arrays are collections of multiple values. In a single array, we can store multiple objects or direct properties. The first element of an array is at index 0, and the last element is at the index value equal to the value of the array’s length property minus 1.here for the array we need to use the third bracket [].

var arr1=[
object1={
name:'Ahmed',
age:31,
occupation:'business',
}
object2={
name:'Rashid',
age:33,
occupation:'Cricket',
}
country:'Bangladesh',
]

Conditional Statement: JavaScript use If.. else for conditional statement. we need to implement different actions for different conditions. In that cases If … else is a game-changer for a cleaner and logical code.

if(condition){
//do the action}
else{
do another action}
Example:
if(salary> 10,00000){
return 'Planning for a new house'
}
else{
return 'keep going, you need to work more'
}

Loops: Loops are useful when we need any repeated works. Basically, JavaScript uses three kinds of loops -do…while, while, and for loops.

  1. do… while the statement repeats the action until the condition comes to a false value.
var value = 0;
do{
value+=1;
console.log(value);
}
while(value<10)
result will be 1 2 3 4 5 6 7 8 9 10

2. while loop runs until its conditions come to the true value.

while(condition){
//do an action
}
Example:
var value=0;
while (value < 10) {
console.log(value); value++;
}
result will 0 1 2 3 4 5 6 7 8 9

3. for loop runs until its specified condition comes to a true value.

for ([initialExpression]; [conditionExpression]; [incrementExpression]){
// do an action
}
Example:
for(let i = 0; i < 10; i++) {
console.log(i)
}
result will 0 1 2 3 4 5 6 7 8 9

Variables: we use var, let, const these three keywords to declare any variables in JavaScript.

var is a global scope variable. that means if you declare a variable with var outside a function, you can still access that variable from inside the function and outside the function as well.

var person = "Amir";

// code here can use person

function myFunction() {
// code here can also use person
}

Both Let and const are block scope variables. which means if you declare a variable with let or const inside a function that variable can be accessible inside that function only.

function myFunction() {
let person = 'Amir'
// code here can use person
}
//code here cann`t use person

the only difference between let and const is that let value can be changed but the value of const. the value of the variable declared with const will be constant.

for(let i = 0; i < 10; i++) {
console.log(i)
}
// here i value will be changed from 0 to 9 until it`s satisfy the condition.
const country = 'Bangladesh';
// the country name will not be changed .it will remain same for whole execution.

Operators: JavaScript’s numeric operators are , +, -, *, /, %.

++ or — is used to increment or decrement respectively.

In this blog, I just tried to summarize the basic basic ten topics from Javascript. In the future will try to continue writing for other topics too. Till then keep learning.

--

--