JavaScript Basic Concept. Overview
By: Ahmed Reza Shah
Tags: String, JavaScript, Arrays, Function, Variables

JavaScript is an open and cross-platform scripting or programming language that allows you to implement complex features on web pages. JavaScript is easy to implement because it is combined with HTML.

Number

First of all, the number is a primitive data type in JavaScript. Number type represents integer, float, hexadecimal, octal value. The Number type introduces some default properties. Since JavaScript uses primitive values as an object, so all the properties and methods apply to both primitive number values and number objects. We can convert a string to an integer using a built-in function called parseInt(). We can also convert a string to floating-point numbers using a built-in function called parseFloat() in JavaScript.

Example:

JavaScript Number

String

In JavaScript string is zero or more characters written inside quotes. It stores a series of characters like “Ahmed Reza Shah”. Strings are used for storing and managing text. String indexes are zero-based. Here the first character is in position 0, the second in 1, and so on.

Example:

JavaScript String

Variable

Variable is something that can vary. Variables hold the data value. You can change a variable as it changed anytime. Generally, we declare a variable with the var keyword in JavaScript. After that, the variable has no value. But technically it has an undefined value.

Example:

JavaScript Variable

Conditional Statement

JavaScript includes if-else conditional statements to control the program flow like other programming languages. There are three types of conditions: if condition, if-else condition, and else-if condition. When we need to execute something based on some condition, then we can use if condition. When we want to execute the code whenever if condition evaluates to false, we use else condition. When we want to apply the second level condition after the if statement, we use the else-if condition.

Conditional Statement

Operators

The operator produces some operation on single or multiple operands then produces a result. For example: 7 + 5 , where + sign is an operator. 7 is a left operand & 5 is the right operand. ‘+’ operator adds two numeric values and produces a result which is 13 in this case.

Example:

Assign values to variables and add them together

Objects

In JavaScript, an object is like any other variable. The only difference is that an object holds multiple values in terms of properties and methods. JavaScript is designed on a simple object-based paradigm. Here Values can be passed to a function, and the function will return a value. So you can say, In JavaScript, functions are first-class objects. Because they have properties and methods just like all other objects. That’s why they are Function objects.

Example:

JavaScript object

Function

A function is a block of code designed to perform a particular task in JavaScript. A function is a group of reusable code which can be called anywhere in the program. This removes the need of writing the same code again and again. Functions let a programmer split a big program into a number of small and manageable functions.

Example:

JavaScript Function

Arrays

An array is a special type of variable, which can able to store multiple values using a special syntax. Every value is connected with a numeric index starting with 0. Array is used to store a collection of data. But it is more useful to think that an array is a collection of variables of the same type.

Example:

JavaScript Array

Some important methods of array are:

pop() method removes the last element from an array.

push() method adds a new element to an array (at the end).

shift() method removes the first array element.

unshift() method adds a new element to an array (at the beginning).

splice() method can be used to add new items to an array.

slice() method slices out a piece of an array into a new array.

Math

Math is a built-in object that allows you to perform mathematical tasks in JavaScript. It works with the number only.

Some important methods of math are:

math.round() method returns the nearest integer number.

math.sqrt() method returns the square root of a number.

math.ceil() method returns rounded up to its nearest integer.

math.floor() method returns rounded down to its nearest integer.

math.random() method returns a random number.

Null & Undefined

In JavaScript, you can say null represents a value which is “empty” or “undefined”. It’s a primitive value of javaScript. Undefined is also a primitive value in JavaScript. A variable or an object has an undefined value when no value is assigned before using it. So you can say that undefined means lack of value or unknown value.