Little glimpse of Javascript features

Samanwoy Saha
Nov 2, 2020 · 6 min read
Image for post
Image for post

Introduction:

Javascript is asynchronous, single-threaded, non-blocking scripting language which sometime appears as a toy in the initial stage but it has huge root under the ground. That’s why it is a must for web developers for building high profile applications. It has destined to run as a scripting language in hosting environment like browser.

History:

Javascript was created by Brendan Eich who was an engineer at Netscape in 1995. Early, it was called Livescript. But due to utilize the popularity of Java it was renamed Javascript later. This creates the all source of confusion although this to language have very few in similarity. After several years Netscape gives Javascript to Ecma International which gives a new look to Javascript as ECMAScript 3(ES3) in 1999, ES5 in 2009 and ES6 as a major edition in 2015.

Overview of some specific Javascript features:

There is no such thing as integer. Every integer explicitly appears as a integer but implicitly it’s a float.

Image for post
Image for post

parseInt(value, base) converts a string to number and takes two parameter value and number base(line 1,2).

Image for post
Image for post

If you put ‘0’ before value like ‘011’ it gives 11 as normal output but if you put ‘0x’ before value like ‘0x11’ it gives 17. But why? Because ‘0x11’ is considered as hexadecimal number.

Image for post
Image for post

parseFloat(value, base) uses 10 base number system as default(line 5).

Image for post
Image for post

Unary operator can also be used to convert a string to a number(line 6).

Image for post
Image for post

Difference between parsing string with parseInt or parseFloat and unary operator is parseInt or parseFloat parse upto a point where number format is not valid returns the valid format. On the other hand, unary operator returns NaN(not a number if anything other than number is in the value otherwise returns the number).

Image for post
Image for post

A special value NaN (Not a Number) is returned if the value is not a number. If any operator is made with NaN it also gives NaN. isNaN( ) method is used to check whether it’s NaN or not.

Image for post
Image for post

Infinity and -Infinity are the two special values which are derived from anyNumber/0 and -anyNumber/0. isFinite( ) method is used to check a number whether it’s finite or not.

Image for post
Image for post

String is a series of unicode characters. In a precise manner, it’s a series of UTF-16 code units and each code units has 16-bit number.

Some Useful methods and objects:

str.length => returns length of string

str.toUpperCase => make all letters uppercase

str.toLowerCase => make all letters lowercase

str.charAt(index) => returns a character at the mentioned index position

str.includes(search string) => returns true or false if the search string is in the existing string or not

Image for post
Image for post

str.replace(old string, new string) => returns string with the partial replaced string.

Image for post
Image for post

Null is a value which represents for non-value and only accessed by null keyword. Undefined is a value of type undefined which represents a variable without assigning value and it’s actually a constant.

trim( ) method removes the white space in the beginning and end of the string. But trimStart( ) only removes the beginning white space of string and trimEnd( ) removes only the ending white space.

Image for post
Image for post

false, 0, empty string(“ ”), NaN, null, undefined are called falsy value. And all other value except above are called truthy value.

One things to keep in mind. Falsy values doesn’t literaly means boolean false because it contains 0, empty string etc. which are not really boolean false but falsy value.

Image for post
Image for post

Scope is the area where it is accessible or visible.

8.1 Global Scope

There is only one global scope in the Javascript Document and this is area outside all functions are declared. All variables declared in this scope is visible everywhere.

Image for post
Image for post

8.2 Local Scope

When a variable is declared inside function, it’s called local variable and it is only accessible to it’s local scope of that function.

Image for post
Image for post

Local Scope can be classified into two categories which are Function Scope and Block Scope (introduced in ES6 with new ways to declare variable with let and const keywords)

8.3 Function Scope

Accessibility of a variable only within function which is declared inside is called Function scope. var keyword is example for function scope accessiblity within function.

Image for post
Image for post

8.4 Block Scope

Area within any curly braces whether it is if-else or for loop is called block. let and const keywords are used to declare variable inside corresponding block scope.

Image for post
Image for post

8.5 Lexical Scope

It indicates the accessibility of children to use their corresponding parent scope variables. It bounds within the context of their parent scope.

Image for post
Image for post

let and const is used for block scope and var is used for function scope. Function scope is accessibility area within function and block scope is within curly braces.

Math.abs(x / y) => returns absolute value of x/y.

Math.min(1, 3, 5) => returns smallest value that passed into it.

Math.max(1, 3, 5) => returns largest value that passed into it.

Image for post
Image for post

Math.ceil(x / y) => returns round value of next largest integer of x/y. if null is given as input Math.ceil(null) returns 0 not NaN.

Math.floor(x / y) => returns round value of previous largest integer of x/y.

Image for post
Image for post

every( ) checks all values in an array according a condition whether it fullfills or not and returns a boolean value.

filter( ) checks all values in an array and returns the values within a new array which fullfills a special condition given to it.

find() checks the values in an array according a given condition and returns the first value that fullfills it in this array.

Image for post
Image for post

pop( ) removes the last element from an array and shift( )removes the first element from an array. Both of those returns the removed item.

Image for post
Image for post

push( ) adds a value to the end of an array and unshift( ) adds a value to the beginning of an array. Both of those returns the new length of the array.

Image for post
Image for post

The Startup

Medium's largest active publication, followed by +775K people. Follow to join our community.

Medium is an open platform where 170 million readers come to find insightful and dynamic thinking. Here, expert and undiscovered voices alike dive into the heart of any topic and bring new ideas to the surface. Learn more

Follow the writers, publications, and topics that matter to you, and you’ll see them on your homepage and in your inbox. Explore

If you have a story to tell, knowledge to share, or a perspective to offer — welcome home. It’s easy and free to post your thinking on any topic. Write on Medium

Get the Medium app

A button that says 'Download on the App Store', and if clicked it will lead you to the iOS App store
A button that says 'Get it on, Google Play', and if clicked it will lead you to the Google Play store