JavaScript is the dialect of the Web. It was presented in 1995 by Netscape, the organization that made the main program by a similar name. Different programs pursued, and JavaScript immediately picked up acknowledgment as the true customer side scripting dialect on the web. Today it is utilized by a large number of sites to include usefulness and responsiveness, approve frames, speak with the server, and significantly more. 

Initially, JavaScript was named LiveScript yet was renamed JavaScript as an advertising system to profit by the detonating ubiquity of the Java programming dialect around then. As it turned out, Java developed into a server-side dialect and did not prevail on the program, though JavaScript did. The difference in name is disastrous in light of the fact that it has caused a considerable measure of perplexity. 

Not long after its underlying discharge the JavaScript dialect was submitted to ECMA International - a universal non-benefit benchmarks association - for thought as an industry standard. It was acknowledged and today we have an institutionalized form which is called EcmaScript. There are a few usage of the EcmaScript standard, including JavaScript, Jscript (Microsoft), and ActionScript (Adobe). The EcmaScript dialect is experiencing persistent enhancements. The following guidelines discharge is EcmaScript sixth release and is code named "Congruity". 

At first numerous engineers felt it was a second rate dialect in light of its apparent effortlessness. Additionally, clients would much of the time cripple JavaScript in their programs in view of security concerns. Notwithstanding, in the course of the most recent couple of years, beginning with the presentation of AJAX and the related Web 2.0 progress, it turned out to be evident that JavaScript enables engineers to fabricate amazing and very responsive web applications. Today JavaScript is viewed as the Web dialect and a fundamental instrument for building present day and responsive web applications. 

A few designers are thinking that its hard to begin building genuine applications with JavaScript; specifically those that are originating from develop, protest arranged, statically-composed dialects, for example, Java, C++, and C#. This is reasonable in light of the fact that JavaScript is progressively composed and a somewhat sympathetic dialect which makes it simple to program, yet additionally simple to commit errors. Also, mix-ups and coding blunders in JavaScript can be exceptionally hard to recognize in view of moderately juvenile designer devices, for example, editors, compilers, debuggers, incorporation, organization, and so on. Luckily, better tooling is quickly getting to be accessible in any case, for instance, JavaScript's alarm is likely still the most generally utilized investigating office. 

In this instructional exercise we cover the JavaScript dialect and we will feature those parts of the dialect that are difficult and mistake inclined. We will disclose how to maintain a strategic distance from these. 

On the off chance that you will probably compose powerful and very much organized JavaScript code you might need to investigate our interesting JavaScript + jQuery Design Pattern Framework. It gives nitty gritty data on the most proficient method to appropriately sort out and manufacture JavaScript web applications utilizing demonstrated plan examples and best practice strategies. You will figure out how to keep away from the numerous traps and risks that are a piece of the JavaScript dialect. Rather than pursuing elusive bugs, you and your group can concentrate on building all around organized, effectively viable, adaptable, and wonderful web applications. 

How is JavaScript identified with Java? 

A typical misguided judgment is that JavaScript is firmly identified with Java. The facts demonstrate that the two dialects have a C-like language structure yet that is the place the comparability closes. With Java you can make independent applications, yet this isn't the means by which JavaScript works. JavaScript requires a facilitating domain which most regularly is the program. The JavaScript code is installed in HTML records and its essential utilize is to add intelligence to HTML pages. Numerous engineers don't understand this, yet JavaScript itself does not have the offices to give information and yield to the client, it depends on the DOM and the program for that. 

Another distinction is that Java is statically composed while JavaScript is a powerfully composed dialect. In a statically composed dialect (e.g. Java, C#, C++) you pronounce factors that are of a particular kind, for example, whole number, twofold, or string. At runtime these sorts don't change. Allocating a string to a whole number variable will result in a blunder. 

/Java 

int add up to = 131; 

add up to = "This is Java";/Error. Truth be told, won't arrange 

In JavaScript, which is a progressively composed dialect, a variable can hold any kind of significant worth, for example, number, string, Boolean, and so on. In addition, at runtime, the sort can be changed. For example, a variable that is bound to a number can undoubtedly be re-relegated to a string. 

Here is a precedent where a similar variable is allocated to a number esteem, a string, a question, and even a capacity; and everything works fine: 

/JavaScript 

var add up to = 131;/number 

add up to = "This is JavaScript";/string 

add up to = {"Customer": "Karen McGrath"};/protest 

add up to = work () {alert("Hello");};/work 

add up to();/=> Hello (executes work) 

Both Java and JavaScript acquire their programming language structure from C. For instance, for, do while, while circles, and if, switch, break, and proceed with explanations all exist in JavaScript. Here are a few precedents: 

for circle 

var check = 0; 

for (var I = 0; I < 10; i++) { 

check += I; 

alert("count = " + check);/=> tally = 45 

while circle 

var I = 0; 

check = 100; 

while (I < count){ 

i++; 

alert("i = " + I);/=> I = 100 

switch proclamation 

/switch proclamation 

var day = new Date().getDay(); 

switch(day) { 

case 0: 

alert("Today is Sunday."); 

break; 

case 1: 

alert("Today is Monday."); 

break; 

case 2: 

alert("Today is Tuesday."); 

break; 

case 3: 

alert("Today is Wednesday."); 

break; 

case 4: 

alert("Today is Thursday."); 

break; 

case 5: 

alert("Today is Friday."); 

break; 

case 6: 

alert("Today is Saturday."); 

break; 

default: 

alert("Today is a weird day."); 

in the event that else 

var esteem = 9; 

in the event that (esteem < 0) { 

alert("Negative value."); 

} else if (esteem < 10) { 

alert("Between 0 and 9, inclusive."); 

} else { 

alert("Greater than or equivalent to 10."); 

break and proceed 

for (var I = 0; I < 100; i++) { 

in the event that (I < 5) { 

proceed; 

} else in the event that (I > 7) { 

break; 

alert(i);/=> 5, 6, 7 

attempt, get 

attempt { 

doesNotExist(); 

get (ex) { 

alert("Error: " + ex.message);/=> Error subtle elements 

Perusing 

Most dialects bolster square dimension perusing. Square dimension factors just exist inside the setting of a square of code, for example, an if or a for articulation. In the Java precedent beneath, the variable tally just exists inside the wavy props. It isn't obvious or available outside the square. 

/Java 

in the event that (acknowledge == genuine) { 

int check = 0;/square dimension scope 

... 

What is Javascript?

Capacity level extension 

In JavaScript there is no square dimension checking, however it supports work level perusing. Capacity level factors that are announced inside a capacity are just accessible and unmistakable to that work. 

/JavaScript 

work ascertain () { 

var tally = 0;/work level degree 

... 

JavaScript's worldwide degree 

JavaScript factors that are proclaimed outside capacities have worldwide degree and are unmistakable to the whole program. 

/JavaScript 

var acknowledge = genuine;/worldwide degree 

in the event that (acknowledge === genuine) { 

var tally = 0;/worldwide degree 

As a JavaScript engineer, it is important that you comprehend perusing and related subjects, since it has essential ramifications on the most proficient method to best your structure your code. The JavaScript + jQuery Design Pattern Framework incorporates examples and arrangements identified with perusing including terminations, modules, and namespacing which will make your life as a JavaScript designer a ton less demanding. You can take in more here. 

Ending semicolons 

Proclamations in JavaScript are delimited with semicolons. You can discard semicolons in light of the fact that the JavaScript motor has an auto-addition system which includes semicolons where it supposes they are absent. The issue is this may cause unintended reactions. 

Hence, you ought to dependably end your announcements with semi-colons unequivocally. The following is a case of what JavaScript looks like at articulations uniquely in contrast to what the engineer planned. 

Consider these 2 explanations without semi-colons: 

/against example! 

whole = total1 + total2 

(total3 + total4).x() 

JavaScript will decipher this as: 

whole = total1 + total2(total3 + total4).x(); 

Here is another case of what can turn out badly: 

/hostile to design! 

work sumSquared(x,y) { 

return 

(x * x) + (y * y); 

alert(sumSquared(3,4));/=> unclear 

This capacity will dependably return unclear on the grounds that it executes the code with a semicolor following return: 

work sumsquared(x,y) { 

return;/semicolon included! 

(x * x) + (y * y); 

A Beginner’s Guide to JavaScript

JavaScript is pitifully composed 

As referenced previously, JavaScript is a pitifully composed dialect. A variable can be bound to any information type and after that change its sort. For example, a variable with an estimation of 1 can be changed to "Hi", trailed by a protest task.

Now and again this has befuddling results. For instance, when JavaScript experiences the articulation "2" + 1, it verifiably changes over the numeric 1 to a string and returns the string "21". Indeed, even the articulation invalid + 0 is lawful in JavaScript and returns 0. Such certain changes can cause program mistakes that are hard to identify. 

alert(null + 34);/=> 34 

Useful programming 

JavaScript bolsters a practical programming style. Capacities in JavaScript are top notch subjects which it gets from the Scheme programming dialect. Indeed, capacities are objects and in this way a capacity can likewise have properties and techniques. 

There is more you can do with capacities; you can store them in factors, passed them around as capacity contentions, and return them as the arrival estimation of a capacity. In JavaScript the contrast among code and information can be hazy on occasion, a trademark it acquires from the Lisp programming dialect. Here is a case of a capacity alloted to a variable. The capacity is executed by affixing the variable name with two enclosures. 

var say = work() { 

alert("Hello"); 

}; 

say();/=> Hello 

Next is a case of a capacity that is passed as a contention to another capacity: 

var say = work() { 

alert("Hello"); 

}; 

work execute(callback) { 

callback(); 

execute(say);/=> Hello 

What's more, here is a case of a capacity that is returned by another capacity: 

work go() { 

return work() { 

alert("I was returned"); 

}; 

var result = go(); 

result();/=> I was returned 

JavaScript bolsters capacities settled inside different capacities. The settled capacities are called techniques. Techniques approach all parameters and nearby factors of the capacities it is settled inside. The following is a precedent where the settled say work approaches the name variable in the external capacity: 

work person(first, last) { 

var name = first + " + last; 

work say() {/strategy, settled capacity 

alert(name); 

say(); 

}; 

person("Joe", " McArthur ");/=> Joe McArthur 

Exhibits are additionally protests and the worked in cluster strategies, for example, guide, channel, and diminish have the qualities of a practical programming style; so they likewise approach all exhibit esteems. Exhibits are talked about later. 

JavaScript is question arranged, however class-less 

JavaScript does not bolster classes, but rather questions assume a focal job. Since there are no classes you may ponder 1) how are objects made, and 2) does JavaScript bolster legacy? The short answers are: there are a couple of various approaches to made items and to the extent legacy, truly, JavaScript supports legacy yet through a system that utilizes models. The class-less, prototypal nature of JavaScript will be investigated in a matter of seconds, however first we'll audit the sorts and protests upheld by JavaScript. 

First the fundamental sorts: JavaScript offers a few crude sorts: Numbers, String and Booleans, and furthermore invalid sort and indistinct sort. The initial three, Numbers Strings, and Booleans, do have properties and techniques however they are not objects. When perusing a property or strategy from these sorts, JavaScript makes a wrapper question, by calling the Number(), String(), or Boolean() constructor in the background. You can likewise expressly make these wrapper objects yourself. The following is a model where JavaScript certainly (i.e. in the background) utilizes the String constructor to play out a substring activity. The second model uses the Number constructor to change over the number to a string while at the same time keeping just two decimals 

var content = "magnificent"; 

alert(text.substring(0,5));/=> exceed expectations 

var tally = 20.1045; 

alert(count.toFixed(2));/=> 20.10 

Articles 

A JavaScript question is an accumulation of properties where every property has a name and an esteem. Simply envision it as a structure made up of key-esteem sets. In more formal terms, JavaScript objects are acquainted clusters - like Hash, Map, or Dictionary in different dialects. 

At runtime, you can make an unfilled protest and afterward include properties of any kind, for example, crude sorts, different questions, and capacities to the question. Properties and qualities can be adjusted and erased anytime. Properties can be specified utilizing the for-in circle. How about we take a gander at a few models: 

/Note: the utilization of new Object() is commonly debilitated 

var o = new Object(); 

o.firstName = "Joan"; 

o.lastName = "Holland"; 

o.age = 31; 

alert(o.firstName + " + o.lastName);/=> Joan Holland 

alert(typeof o.age);/=> number 

erase o.firstName; 

alert(o.firstName + " + o.lastName);/=> unclear Holland 

for (var prop in o) 

/name: firstName, esteem: Joan, type: string 

/name: age, esteem: 31, type: number 

alert("name: " + prop + " ,esteem: " + o[prop] + 

" ,type: " + typeof o[prop]); 

In this model an unfilled protest is made. At that point three properties are included by doling out two strings and a numeric esteem. In the wake of showing the qualities and the number sort, the firstName property is erased. At long last, a for-in circle shows the rest of the properties (with name, esteem, and type) on the question. 

There are 3 classifications of items in JavaScript: 

1. Inherent (local) objects like Math, Date, and Array 

2. Client characterized objects like Book, Employee, and so on., and 

3. Host objects characterized by the runtime condition (typically the program, for example, DOM objects 

also, the window worldwide protest. 

Protests in the initial two classes comply with the EcmaScript particular. In any case, objects made accessible by the facilitating condition are outside the domain of EcmaScript. 

Capacities 

The code beneath affirms that capacities are for sure protests in JavaScript 

work say(name) { 

alert("Hello " + name); 

alert(typeof say);/=> work 

alert(say instanceof Object);/=> genuine 

say.volume = "high"; 

alert(say.volume);/=> high 

The capacity is of sort work, however it is likewise an occurrence of sort Object. In the last two lines a property named volume is allocated to the protest without an issue, affirming that it carries on like a question. 

Capacities can likewise be utilized to make questions; these are called constructor capacities. First you proclaim a capacity and afterward dole out properties and capacities (i.e. techniques) utilizing the this watchword. This model doles out two properties and one technique to this. 

Conditional JavaScript for Experts

work Book (title, writer) { 

this.title = title;/book properties 

this.author = creator; 

this.details = work() {/book technique 

return this.title + " by " + this.author; 

By tradition, constructor capacities begin with a capitalized letter (i.e. Book). 

At the point when a constructor work is called with another administrator it will make another book case. Inside, the capacity makes another clear question and ties it to this. At that point it executes the capacity body which usually doles out properties and strategies to this. Toward the end the capacity restores the recently made questions by an understood restore this announcement. 

In the code underneath another Book occasion is made and we conjure its points of interest strategy: 

var book = new Book("Ulysses", "James Joyce"); 

alert(book.details());/=> Ulysses by James Joyce 

Capacities and items are not by any means the only protests in JavaScript; clusters are articles and ordinary articulations are questions moreover. 

A property of a protest can be another question, which thus can have at least one items. Every one of these items give a great deal of adaptability and permit the production of complex tree and diagram structures. 

JavaScript is a model based dialect 

JavaScript has no classes, just questions. Things being what they are, without classes, is there maybe another way that items can get usefulness from different articles? As such, is legacy upheld by JavaScript? The appropriate response is yes; you can accomplish legacy by utilizing models. This is called prototypal legacy, an idea acquired from a dialect named Self. Prototypal legacy is understood, which means it exists regardless of whether you don't do anything extraordinary. 

How about we take a gander at prototypal legacy. Each question in JavaScript is connected to a model protest from which it acquires properties and techniques. The default model for a protest is Object.prototype. You can get to this property by means of a property called model. In the code beneath we have a constructor capacity and check its model property. This is the model question that will be appointed to each book occasion that is made by this constructor work. 

var Book = function(author) { 

this.author = creator; 

}; 

alert(Book.prototype);/=> [object Object], so there is something 

Since each question has a model, it is anything but difficult to envision a progression of items connected together to shape a model chain. The start of the chain is the current question, connected to its model, which, thusly, is connected to its very own model, and so on the distance until the point that you achieve the root model at Object.prototype. 

Following the model chain is the way a JavaScript protest recovers its properties and qualities. While assessing an articulation to recover a property, JavaScript decides whether the property is characterized in the protest itself. In the event that it isn't discovered, it searches for the property in the quick model up in the chain. This proceeds until the point that the root model is come to. On the off chance that the property is discovered, it is returned, generally unclear is returned

Each capacity in JavaScript consequently gets a model property including constructor function(s). When you utilize a capacity as a constructor, its model property is the question that will be appointed as the model to all occasions made. Here is a precedent: 

work Rectangle (width, tallness) { 

this.width = width; 

this.height = tallness; 

Rectangle.prototype.area = work () { 

return this.width * this.height; 

}; 

var r1 = new Rectangle(4, 5); 

var r2 = new Rectangle(3, 4); 

alert(r1.area());/=> 20 

alert(r2.area());/=> 12 

In the precedent, r1 and r2 objects are made by a similar constructor, so they both acquire from a similar model which incorporates the territory strategy. 

There is impressive perplexity encompassing models and prototypal legacy among JavaScript engineers. Numerous books, online journals, and different references characterize prototypal legacy yet tragically most are somewhat fluffy and need clear code tests. 

Our JavaScript + jQuery Design Pattern Framework is intended to tackle this perplexity for the last time. It makes you stride by-venture through JavaScript's model framework with straightforward graphs and clear code tests. It might take 20 minutes or more, yet once you 'get it' your comprehension of JavaScript will have gone up exponentially - also your trust in the dialect. 

JavaScript's runtime and facilitating condition 

At the point when JavaScript was first discharged the dialect was deciphered. The source code would be parsed and execute promptly without fundamental assemblage into byte code. In any case, ongoing variants of programs incorporate exceedingly upgraded JavaScript compilers. Normally this includes the accompanying advances: first it parses the content, checks the linguistic structure, and creates byte code. Next, it takes the byte code as info, creates local (machine) code, and afterward executes it on the fly. 

JavaScript applications require a domain to keep running in. The JavaScript translator/JIT-compiler is executed as a major aspect of the host condition, for example, an internet browser. The content is executed by the JavaScript motor of the internet browser, which is by a wide margin the most well-known host condition for JavaScript. 

All the more as of late JavaScript is additionally being utilized outside the program. Models incorporate Mozilla's Rhino and node.js – the last is a Chrome-based stage to assemble quick, adaptable system applications. JavaScript is likewise found on the work area with applications like Open Office, Photoshop, Dreamweaver, and Illustrator, which permit scripting through JavaScript type dialects. 

JavaScript is a little dialect; it characterizes fundamental sorts, for example, strings, numbers, and a couple of further developed items and ideas, such Math, Date, ordinary articulations, occasions, protests, works, and exhibits. Be that as it may, JavaScript does not locally be able to get contribution from the client and show yield back to the client. Neither does it give an API to designs, systems administration, or capacity. For this, it needs to depend on its facilitating condition. With JavaScript running in a program, to discuss forward and backward with the client, it needs to associate with the archive protest display, normally known as the 'DOM'. 

DOM is an inward portrayal of the HTML components that show up in a page. At the point when the program stacks a page, it manufactures the page's DOM in memory and after that shows the page. The HTML components that speak to the structure of a site page are called have objects that give unique access to the host condition. In view of client input, your JavaScript code changes the DOM and as an outcome the site page is refreshed. Each bit of content, tag, trait, and style can be gotten to and controlled utilizing the DOM API. The record protest gives you a chance to work with the DOM. A straightforward method to interface with the client is to utilize document.write which composes a message specifically into the page (take note of: the utilization of document.write is commonly not prescribed). 

Callback Function In Javascript & Node.JS Explained With Example

var today = new Date(); 

var day = today.getDay(); 

in the event that (day === 0 || day === 6) { 

document.write("It's weekend"); 

} else { 

document.write("It's a weekday!"); 

Consider the accompanying textbox on the site page: 

<input id="email" type="text"/> 

Here is the means by which you can access and change this component on the page: 

var email = document.getElementById("email");/gets ref to textbox 

email.disabled = genuine;/handicap textbox 

var address = "me@company.com"; 

document.getElementById("email").value = address;/refresh esteem 

At the point when JavaScript keeps running in the program, it makes an uncommon question accessible called window which is the worldwide protest. Note that window isn't a piece of the standard JavaScript dialect, however part of the facilitating condition. The ready strategy for the window protest is generally used to show messages in an exchange enclose the internet browser. Since window is a worldwide question, JavaScript gives you a chance to utilize this technique without prefixing it with the window protest name and spot administrator. 

At the point when JavaScript isn't running on the program an altogether extraordinary arrangement of host items will be made accessible by the facilitating condition. For instance, node.js which is facilitated on server machines oftentimes cooperates with HTTP ask for and reaction objects permitting the JavaScript program to produce website pages at runtime; in fact altogether different from the program. 

What's new in EcmaScript 5 

EcmaScript is the official, institutionalized adaptation of JavaScript and a few surely understood executions exist, including JavaScript, Jscript (Microsoft) and ActionScript (Adobe). 

EcmaScript form 5 (ES 5) was presented in late 2009. This rendition includes some new highlights, for example, getters and setters, which enable you to manufacture helpful alternate routes for getting to and changing information inside a question (like C# properties). Likewise new is worked in help for JSON, with techniques, for example, JSON.parse() and JSON.stringify(), evacuating the need to utilize outside libraries to work with JSON. 

What's more, ES 5 included "strict mode", a component which plans to implement a limited variation of the dialect by giving exhaustive mistake checking and making the contents less blunder inclined, less difficult, more decipherable, and solid. You empower strict mode, by including "utilize strict"; as the principal line to your content, as so: 

"utilize strict"; 

var content = "Truly, I'm strict at this point!"; 

This will apply strict mode to the whole content. You should be cautious while linking distinctive contents from various sources, in light of the fact that strict mode will apply to all contents and you may incorporate content that was not intended to keep running in strict mode, which is probably going to cause blunders. 

To unravel this you can restrict the extent of strict mode to a capacity by including "utilize strict"; as the main line in the capacity body, as so 

work f() { 

"utilize strict"; 

... 

Including "utilize strict"; changes both grammar and runtime conduct. For instance, strict mode keeps you from inadvertently making worldwide factors by necessitating that every factor is proclaimed expressly. On the off chance that you neglect to legitimately announce a variable you will get a mistake. For instance, the accompanying won't work: 

"utilize strict"; 

x = 4;/mistake 

work f() { 

var a = 2; 

b = a;/mistake 

... 

Including a var before x and before b will settle the issue. 

Strict mode denies (i.e. expostulates) certain bothersome highlights incorporating the with() build, the arguments.callee include, and octal numbers; on the off chance that it experiences any of these JavaScript will toss a blunder. Besides, the utilization of specific watchwords is confined; for example for all intents and purposes all endeavors to utilize the catchphrases eval and contentions as factor or capacity names will toss a mistake. 

var eval = 10;/mistake 

work getArea(eval){}/mistake 

work eval(){}/blunder 

var contentions = [];/blunder 

In light of security concerns, the utilization of eval() is commonly disheartened, yet you can at present utilize it (even in strict mode). In strict mode, the code go to eval() will likewise be assessed in strict mode. Moreover, eval() does not give you a chance to present new factors which is viewed as hazardous in light of the fact that it might conceal a current capacity or worldwide variable. 

"utilize strict"; 

var code = "var num = 10;" 

eval(code);/variable creation not permitted 

alert(typeof num);/vague (a few programs return number) 

Know that strict mode is at present not solid executed over all programs, and, obviously, more seasoned programs don't bolster it by any stretch of the imagination. It is critical that you test your code with programs that help it and those that don't. On the off chance that it works in a single it may not work in the other and the other way around. 

A simple method to see if strict mode is bolstered is with the accompanying articulation: 

(work() { "utilize strict"; restore !this; })(); 

Here is the means by which you utilize it: 

var strict = (work() { "utilize strict"; restore !this; })(); 

alert(strict);/=> genuine or false 

At the point when strict is genuine you can expect strict mode is bolstered. 

ES 5 has another protest demonstrate which gives extraordinary adaptability on how questions are controlled and utilized. For instance, objects permit getters and setters; they can counteract specification, erasure or control of properties; and they can even square others from including new properties. 

Getters and setters are helpful alternate routes to getting to and changing information esteems in a question. A getter is summoned when the estimation of the property is gotten to (read). A setter is summoned when the estimation of the property is changed (compose). The undeniable favorable position is that the 'private' name variable in the protest is escaped coordinate access. The grammar is fairly ungainly, yet here is a model.

work Person(n){ 

var name = n; 

this.__defineGetter__("name", function(){ 

return name; 

}); 

this.__defineSetter__("name", function(val){ 

name = val; 

}); 

var individual = new Person("John"); 

alert(person.name);/=> John/utilizes getter 

person.name = "Mary";/utilizes setter 

alert(person.name);/=> Mary/utilizes getter 

In ES 5, each question property has a few new traits. They are: enumerable, writable, and configurable. With enumerable you show whether the property can be listed (utilizing a for-in circle); writable demonstrates that a property is variable, and configurable demonstrates whether it tends to be erased or its different qualities can be changed. 

Object.defineProperty is the means by which you characterize these properties and their traits. Beneath we are making a vehicle with 4 wheels. The characteristics guarantee that the wheels property can't be changed or erased, however wheel will show up while repeating over vehicle's properties (with for-in). 

var vehicle = {}; 

Object.defineProperty(car, "wheels", { 

esteem: 4, 

writable: false, 

enumerable: genuine, 

configurable: false 

}); 

car.wheels = 3;/=> not permitted (not writable) 

for (var prop in vehicle) { 

alert(prop);/=> wheels (enumerable) 

erase car.wheels;/=> not permitted (not configurable) 

ES 5 gives two strategies to control question extensibility:Object.preventExtensions keeps the expansion of new properties to a protest, and Object.isExtensible tells whether a question is extensible or not. The model beneath shows their utilization: 

var square shape = {}; 

rectangle.width = 10; 

rectangle.height = 20; 

on the off chance that (Object.isExtensible(rectangle)) {/genuine 

Object.preventExtensions(rectangle);/deny property augmentations 

rectangle.volume = 20;/not permitted 

With ES 5 you can seal a question. A fixed protest won't enable new properties to be included nor will it permit existing properties or its descriptors be changed. Be that as it may, it allows perusing and composing the property estimations. Two strategies bolster this component: Object.seal and Object.isSealed; the first to seal the protest, the second one to decide if a question is fixed. 

var representative = { firstName: "Jack", lastName: "Watson" }; 

Object.seal(employee); 

alert(Object.isSealed(employee));/=> genuine 

employee.firstName = "Tommie";/alright 

Solidifying is comparable to fixing, yet forbids perusing or composing property estimations. The two strategy included are Object.freeze and Object.isFrozen: 

var representative = { firstName: "Jack", lastName: "Watson" }; 

Object.freeze(employee); 

alert(Object.isFrozen(employee));/=> genuine 

employee.firstName = "Tommie";/not permitted

10 things to learn on the way to becoming a JavaScript Master
JavaScript Arrays
JavaScript JSON
JavaScript Operators
Handling Errors in JavaScript: The Definitive Guide