http://www.youtube.com/user/kudvenkat...
Link for slides, code samples and text version of the video
http://csharp-video-tutorials.blogspo...
Just like Java and C#, JavaScript is also an object oriented programming language. However, JavaScript is not very strict in reporting or throwing errors. Let us understand what this statement means with an example.
In C#, if you assign a value to a variable that is not declared, you get an error stating - The name 'myString' does not exist in the current context.
myString = "This is a string";
Where as the same code in JavaScript does not raise any error. JavaScript automatically creates a global variable with name myString. This kind of a behaviour may lead the developer to make more mistakes.
myString = "This is a string";
document.write(myString);
Output : This is a string
Just like Java & C#, if you want JavaScript also to throw an error, then use Strict Mode.
How to enable strict mode in JavaScript : Just add "use strict" statement in your script file as shown below. When you run the page, you will now get an error stating - Variable undefined in strict mode. To see the error in google chrome, please go the console window in developer tools.
[script type="text/javascript"]
"use strict";
myString = "This is a string";
document.write(myString);
[/script]
Since "use strict" is specified at the top of the JavaScript file, strictness will be enforced across the entire script file.
How to enforce JavaScript strictness in a specific function : Just add "use strict" statement in the function as shown below. In this example, strictness is enforced only in myFunction().
[script type="text/javascript"]
myString = "This is a string[br/]";
document.write(myString);
function myFunction()
{ "use strict"; var myOtherString = "This is also a string"; document.write(myOtherString);
}
myFunction();
[/script]
Output :
This is a string
This is also a string
Let us look at another example : In C# if you assign a value to a read-only property you get an error. For example, the following C# code would raise an error stating - Property or indexer 'Demo.Employee.Name' cannot be assigned to -- it is read only.
public partial class WebForm1 : System.Web.UI.Page
{ protected void Page_Load(object sender, EventArgs e) { Employee employee = new Employee("Mark"); employee.Name = "Mark M"; }
}
public class Employee
{ private string _name; public Employee(string name) { this._name = name; } public string Name { get { return this._name; } }
}
We discussed JavaScript properties in Part 58 of JavaScript tutorial.
In JavaScript, if you assign a value to a read-only property, JavaScript silently fails without raising an error.
[script type="text/javascript"] var Employee = function (name) { var _name = name; Object.defineProperty(this, "name", { get: function () { return _name; } }); } var employee = new Employee("Mark"); // name is readonly property. It is an error to assign a value to a read-only property // JavaScript silently fails the following line without raising an error employee.name = "Mark M"; document.write(employee.name);
[/script]
If you want JavaScript to raise an error instead of failing silently, use JavaScript strict mode. The code below raises an error stating - Assignment to read-only properties is not allowed in strict mode.
[script type="text/javascript"] "use strict"; var Employee = function (name) { var _name = name; Object.defineProperty(this, "name", { get: function () { return _name; } }); } var employee = new Employee("Mark"); employee.name = "Mark M"; document.write(employee.name);
[/script]
ECMAScript version 5 introduced strict mode to JavaScript. With strict mode on it is easier to detect JavaScript silent errors as they would throw an error now. This makes debugging much easier and the chances of developers making mistakes is reduced. Most modern browsers support strict mode.
For the list of most important restrictions that apply in strict mode, please refer the following MSDN article
https://msdn.microsoft.com/en-us/libr...
asp.net core docker Strict Mode in JavaScript | |
143 Likes | 143 Dislikes |
30,049 views views | 524K followers |
Education | Upload TimePublished on 16 Feb 2015 |
Related keywords
wcf vs web api,ado.net core,sql server management studio,webkinz,webadvisor,craigslist nj,wcf one piece,asp.net core 3,ajax players,weber grill parts,webtoon,tutorials by hugo,csharp corner,mvc design pattern,asp.net machine account,servers for minecraft,asp.net core dependency injection,ado.net tutorial,services angular,ajax ontario,asp.net mvc tutorial,javascript tutorial date,asp.net cos'è,csharp assembly,javascript tutorialspoint,tutorialspoint python,sql join,services briefcase,asp.net core web api,ajax jquery,wccftech,craigslist ny,asp.net zero,csharp foreach,server memes,sql date format,javascript tutorial example,services online,chase,javascript tutorial callback,serverless architecture,server resume,wcf c#,server books,tutorialspoint javascript,mvcc connect,ado.net mysql,services technologies gps,javascript tutorial indonesia pdf,ajax deadpool,server jobs,cvs,website,mvc tutorial,costco hours,wcf service application,tutorialspoint spring,serverless,wcf soap,javascript tutorial code,wcf cat,wcf test client,cool math games,services & training hse colombia sas,servicestack,citibank,asp.net core identity,sql union,ajax parking,sql database,asp.net core logging,mvconnect,asp.net guida,cunyfirst,wcf nba,csharp download,wcfi foundation,csharp online,wcf authentication,javascript tutorial pdf,tutorials near me,http://asp.net,server 2019,ado.net descargar,web of dreams,chernobyl,serverminer,ajax cleaner,ado.net visual studio 2019,webassign,ado.net vs entity framework,ado.net visual studio 2017,csharp list,sql like,asp.net mvc,asp.net core tutorial,sqlite,wcfm,ajax roster,mvc architecture,http://ado.net,asp.net core mvc,ajax soccer,server hosting,wcfi,ajax dish soap,capital one,server rack,tutorialspoint html,csharp interface,craigslist,webroot,tutorialspoint reactjs,ajax request,wcf dragon ball,asp.net core 2.2,tutorialspoint python 3,sql developer,webster,services transmission company sas,sql group by,asp.net core signalr,services manager,mvc framework,ajax paving,mvc near me,tutorialspoint spring boot,mvc map,csharp online compiler,asp.net download,sql between,ado.net c# pdf,wcf 2019 nba,javascript tutorial download,services tag dell,csharp switch,ado.net ventajas y desventajas,csharpstar,wcf tutorial,javascript tutorial web development,tutorialspoint,ajax meaning,csharp-video-tutorials.blogspot,tutorials dojo,csharp string format,central park 5,ado.net c#,javascript tutorial for beginners,asp.net core github,server status,ajax fc,server jobs nyc,asp.net core swagger,sql formatter,credit karma,services group,server error in '/' application,services windows,asp.net core 3.0,sql injection,wcf ria services,tutorialspoint c#,calculator,ado.net entity data model,sql insert,tutorialspoint tableau,services google play apk,sqlyog,asp.net core 3 release date,sql server,server job description,tutorials by a,servicenow,webcam,mvc hours,javascript tutorial library,webmd symptom,csharp array,javascript tutorial w3,csharp enum,ajax call,asp.net core 2. guida completa per lo sviluppatore,asp.net core,server pro,server status ffxiv,webcrims,cheap flights,asp.net core hosting,services sas,javascript tutorial documentation,tutorialspoint java,tutorialspoint java compiler,webmd,csharp to json,college football,ado.net dataset,csharp dictionary,cnn,website builder,tutorialspoint sql,asp.net web api,server side rendering,weber grills,sql server 2017,mvc nj,tutorialspoint spark,javascript tutorial function,ado.net oracle,asp.net core download,csharp to vb.net,webster bank,webstaurant,tutorialsystems,ajax post,services fms publish announcement,services.msc no abre,ajax jersey,csharp operator,asp.net core razor pages,server duties,asp.net core environment variables,csharp random,century 21,services consultores,services consulting,mvcsd,mvcsc,services.msc,ado.net pdf,asp.net core configuration,ajax marvel,sql update,asp.net tutorial,mvc medical,ado.net entity data model visual studio 2019,wcfs international curriculum,mvc2,javascript tutorial w3school,ado.net entity data model visual studio 2017,javascript tutorial github,chase online,wcf api,costco,server jobs near me,webex,sql meaning,sql tutorial,sql commands,javascript tutorial video,ado.net entity framework,ajax tavern,tutorialsteacher,ajax javascript,javascript tutorial for frontend developers,services desk,ajax greek,csharp tutorial,mvc pattern,ado.net sql server,ado.net connection,asp.net identity,mvcu,asp.net core middleware,wcf web service,mvc webadvisor,web store,mvcc,webmail,mvci,mvctc,
Không có nhận xét nào:
Đăng nhận xét