A to -Z Java Script

Owali Ullah Shawon
6 min readMay 5, 2021

Variable

Varialbes are the declaration of some type of data. Some rules have to apply during the declaration of a variable.

  • You cannot use RESERVE KEYWORD as a variable.
  • A variable name can be started by a letter or with an underscore ( ‘_’ ) Dollar ( ‘$’ ) sign without other special characters !, @, #, %, ^, &, *, (, )
  • You cannot use space within a variable name.
  • You can use CamalCase

DataType

There are two types of DataType.

  • Primitive

❤ Number: (-100, 3.14, and others), used for math calculations.

❤ String: (“hello”, “abracadabra”, and others), used for text.

❤ Undefined: (undefined), used for unintentionally missing values.

❤ Null: used for intentionally missing values.

  • Non Primitive

❤ Array

❤ Object: ({} and others), used to group related data and code.

❤ Function: (x => x * 2 and others), used to refer to code.

Conditional Statement

try….catch

Simple try-catch

The try...catch construct has two main blocks: try, and then catch. Inside the try block if the code executed properly then the catch doesn't work. But if in the try block happens error then we can show these errors on the catch block.

Strings

charAt, concat, includes, endsWith, indexOf, lastIndexOf, replace, slice, split, startsWith, substr, toLowercase, toUppercase, trim, trimStart, trimEnd

The charAt() method of the String object returns a new string containing a single UTF-16 code unit at the given offset into the string.

The concate() function concatenates two or more strings and returns the resulting string.

The includes() method determines whether an array includes a certain value among its entries, returning true or false as appropriate.

The endsWith() method determines whether a string ends with the characters of a specified string, returning true or false as appropriate.

The indexOf() method returns the first index at which a given element can be found in the array, or -1 if it is not present.

The lastIndexOf() method returns the last index at which a given element can be found in the array, or -1 if it is not present. The array is searched backwards, starting at fromIndex.

The replace() method returns a new string with some or all matches of a pattern replaced by a replacement. The pattern can be a string or a, and the replacement can be a string or a function to be called for each match. If pattern is a string, only the first occurrence will be replaced.

The slice() method extracts a section of a string and returns it as a new string, without modifying the original string.

The split() method divides a String into an ordered list of substrings, puts these substrings into an array, and returns the array. The division is done by searching for a pattern; where the pattern is provided as the first parameter in the method's call.

The startsWith() method determines whether a string begins with the characters of a specified string. This method returns true if the string begins with the characters, and false if not.

The substr() method extracts parts of a string, beginning at the character at the specified position, and returns the specified number of characters.

The toLowerCase() method converts a string to lowercase letters. The toUpperCase() method converts a string to uppercase letters.

The trim() method removes whitespace from both ends of a string. The trimStart() method removes whitespace from the beginning of a string. The trimEnd() method removes whitespace from the ending of a string.

Numbers

The isNaN() function determines whether a value is a number or not. The parseFloat() function parses a string and returns a floating-point number. The parseInt() function is used to accept the string,radix parameter and convert it into an integer.

Math.abs Returns the absolute value of the argument.

Math.round Returns the closed int or long (as per the argument)

Math.ceil Returns the smallest integer that is greater than or equal to the argument

Math.floor Returns the largest integer that is less than or equal to the argument

Math.min Returns the smallest of the two arguments

max Returns the largest of the two arguments

Arrays

  • arr.push(...items) – adds items to the end,
  • arr.pop() – extracts an item from the end,
  • arr.shift() – extracts an item from the beginning,
  • arr.unshift(...items) – adds items to the beginning.

The arr.splice method is a swiss army knife for arrays. It can do everything: insert, remove and replace elements.

The method arr.slice is much simpler than similar-looking arr.splice . its create a new array by copy start to end.

The method arr.concet creates a new array that includes values from other arrays and additional items.

The arr.forEach method allows to run a function for every element of the array.

THe indexOf/lastIndexOf mainly includes where find out the position of an element. indexOf find out any position which is searching and the lastIndexOf is for the ending element. After finding it can compare.

Imagine we have an array of objects. To find out the the object with specific condition we will use find & findIndexOf

The function is called for elements of the array, one after another:

  • item is the element.
  • index is its index.
  • array is the array itself.

The find method looks for a single (first) element that makes the function return true. If there may be many, we can use arr.filter()

arr.map is called the function for each element of the array and returns the array of results. Its works like a for loop.

The call to arr.sort() sorts the array in place, changing its element order.

The method arr.reverse the order of elements in array like if an array of [1,2,3,4] then it will be [4,3,2,1]

--

--