You can’t swing a stick in the ASP.NET world without hitting some JavaScript. And even though both languages have curly braces, JavaScript is not C#. This presentation will cover common misconceptions about JavaScript, some hidden gotchas, and areas of danger for C# developers that expect JavaScript to work like C#.
Introduction of selfIntroduction of topicImportance of JavaScriptImportance of knowing it well
What type is the “something” variableBlack and white
The similarities …
And the differences ….These are the falsey valuesDEMO – run once with test undefinedWhat about the word “False”, or the word “false”?
This is where the definition of falsey comes inIf false is like false, and 0 is like false, and you compare them …String / Number comparison can be deadly
Why can’t C# do it? Types
Making JS check the types as wellAlso mention !==
Trivia question: where does the movie variable live? How about anotherMovie? DEMO
DEMO
Talk more about function level scope laterWhere does movie live? Private variable of the function
Because we didn’t tell JS to declare new, it assumes referring to object on the window. Warning from Resharper 6Note that movie won’t be on the WINDOW until the function is calledBonus question – where does the function live?
DEMO
Local, so long as declared in the functionDEMO – prove that movie is local and sequel is global by moving console.log() outside of the block
Why is “efficiency” red?
DEMORewrite code to declare in the right spot
Rewrite the demo
No classDynamic nature
Object literal
DEMO creating objects
Talk about namespaces in C# and XML
DEMO
DEMO – show that now only stldodn is in the global namespaceDEMO – show that message is still in there