JavaScript Fundamentals

JavaScript is syntactically a C family language. We will walk through some fundamentals about JavaScript.
Objects: JavaScript is a object oriented language but in JavaScript object are different thing than other language “JavaScript object is an dynamic collection of properties”,  an properties can be added at any time. Every property has a key string through which we can get the value. Get, Set and delete are three basic operations on an object. Get- use dot or brackets. Set- use the assignment operator. Delete- prefix.
# In JavaScript we have object literals and a way to create object using colons. Name : Value
# Function /array can also have property. arr.prop=3
# Properties can be accessed by bracket syntax   arr[“prop”]
# Using bracket syntax I can add property with space like, arr[“full name“] = “Anshu Kumar”;
# Can add or access properties using loop.
Number:  In javascript we don’t have integers we have Numbers.
NaN is special number. Returned after error nous calculation.
**NaN is not equal to NaN(True).
Strings —
ParseInt- convert value into number
Stops at first non digit number.
we can extend the common functions functionality by prototype.. like for Trim and reverse functions.
Splice(start-index, element-count) : Do not make a hole in the array. Like in case of using delete –undefined value is get added at the deleted place.
Null(was before there) and undefined(not initialized default value of variables) are not object.
**Typeof(null) return Object which is wrong. Null is not a object.

Falsy values ( False, null, undefined,””,0, NaN) if put inside If(..) will return false.
For instatement.. New to javascript
Throw— throw any thing object/ error
Try–will have only one catch clause.

Asynchronous nature:

JavaScript is single threaded means we have single call stack.
JavaScript event loop for Asynchronous callback & call Stack..
Event Loop check the task/callback queue and if there is something it push that thing into the call stack.

In JavaScript declaration are hoisted means a **variable can be declared after it has been used.
x = 5; // Assign 5 to x
var x; // Declare x
Hoisting is quite strange behavior of JavaScript so to avoid bugs one should always declare all variables at the beginning.

Window is the parent of the webpage.Collector of everything i.e. global.

In JavaScript function only create the scopes(inner or outer scope) unlike other languages scope are defined by class, namespace etc.


Set Theory

Closure: The context of an inner function(callbacks) include the scope of outer function. Inner function has access to the outer enclosing function’s variables and global variables.

Context / this :
this pseudo parameter of each function in JavaScript which hold the reference of object of invocation.

The prototype property allows you to add new properties and methods to existing object types.

In next post will explain in detail about JavaScript Functions & Prototypal Inheritance, Scoping and Hoisting.

Leave a Reply

Fill in your details below or click an icon to log in: Logo

You are commenting using your account. Log Out /  Change )

Google photo

You are commenting using your Google account. Log Out /  Change )

Twitter picture

You are commenting using your Twitter account. Log Out /  Change )

Facebook photo

You are commenting using your Facebook account. Log Out /  Change )

Connecting to %s