10 Basic Things About JavaScipt

imam hasan
4 min readMay 5, 2021

JavaScript is an object-oriented, compiled programming language. It is most well-known as the scripting language for Web pages, but it's also used out of browsers like Node, Apache CouchDB, and Adobe Acrobat.

Let's talk about some topics about JavaScript.

1. Increment Operator:

The increment operator (++) adds one to its operand and returns a value.

Syntax: a++ or ++a

Postfix Increment (a++) increments the value of the operand and returns the value before incrementing.

Prefix Increment (++a) increments the value of the operand and returns the value after incrementing.

2. Decrement Operator:

The decrement operator (- -) subtracts one from its operand and returns a value.

Syntax: a- - or - -a

Postfix Decrement (a- -) decrements the value of the operand and returns the value before decrementing.

Prefix Decrement (- -a) decrements the value of the operand and returns the value after decrementing.

3. Ternary Operator:

Conditional statements are used to perform different actions based on different conditions.

We can use an if-else statement like the example below

Or, we can use the ternary operator. This will give the same results with less code

Syntax: condition ? expIfTrue : expIfFalse

You can play with ternary in a more complex way too

4. String Method (indexOf())

The indexOf() method returns the index number of the first occurrence of searched value within the calling string object.

Syntax: indexOf(searchValue), indexOf(searchValue, fromIndex)

The interesting part is if no string is explicitly provided to the serachValue, serachValue will replace with ‘undefined’ and this value will be searched for in the calling string.

5. Converting Number to String:

Converting number to string is very easy. Just add an empty string with the number and the work is done.

6. Array length:

We know that the array length property returns the number of elements in the array.

But there is a tricky thing. Let's look at another example

So we understand that length actually returns the last index+1 as an output.

7. Array method (slice()):

The slice() method returns a shallow copy of an array between a range. It will not change the main array.

Syntax: slice(), slice(start), slice(start,end)

8. String Method (replace()):

The replace() method returns a string by replacing a pattern from some or all matches in the calling string with a replacementString. The pattern may be a string or regular expression. If the pattern is a string it will replace the first occurrence of matches. It will not change the main string.

Syntax: replace(pattern,replacementString)

9. Number.parseFloat() method:

This method will parse an argument into a floating-point number. If the argument cannot be parsed, this method simply returns NaN (not a number).

Syntax: Number.parseFloat(string) or parseFloat(string)

parseFloat() parse a string until they reach a character that isn’t a valid number format, then return the number parsed up to that point.

10. Number.parseInt() method:

This method will parse an argument into an integer number of a given base. The base is 10 by default.

Syntax: Number.parseInt(string) or parseInt(string), Number.parseInt(string,base)

parseInt() parse a string until they reach a character that isn’t a valid number format, then return the number parsed up to that point.

--

--