SlideShare a Scribd company logo
1 of 16
KNOWLEDGE TRANSFER AND
SHARING
(Java script Common Mistake’s)
Syntax Error
1. Missing Semicolon (;)
println(“n Welcome 1”) ; // Missing
for(var i= 0 ;i<10;i++)
2. Missing curly braces ({}).
for(var i= 0 ;i<10;i++){ } // Missing
function test (){ } // Missing
3 . Missing Open close braces ().
function test ( param1,param2 ) // Missing
4. Missing Commas (,).
var a = “A’” ,b = “B” // Oops, missing ',' here!
c = “C”, d = “D”;
JavaScript Is
case sensitive
• JavaScript is very case sensitive.
• Example :
function test1(inputContext){
println( “n inputContext ”+InputContext);
}
inputContext is different from InputContext.
Confusion between Concatenation and
Addition
1. Println (10 +2)
Type of 2 is Number – Addition
-- result : 12
2. Println (10 + “2”)
Type of 2 is String – Concatenation
--result : 102
Confusing single and
double quotes
1. Println ('Two’);
-- result is Two
2. Println ("Two's");
-- result is Two’s
3. Println ('Two's');
-- Error
Variable
without - var
• JavaScript is very permissive.
• It will silently declare it for you globally.
• Memory Leakage.
• Significantly reduce the chance of bad
interactions with other applications libraries.
Differentiate float numbers
from integer numbers
• Example:
var myNumber = 3.5;
var myResult = 3.5 + 1.0; //We use .0 to keep the result as float
1. No difference between float and integers.
2. Don’t use decimals to “convert” numbers to
floats.
var myNumber = 3.5;
var myResult = 3.5 + 1; //Result is 4.5, as expected
Don't Use Short Hand
• Curly braces should be omitted is with one-liners.
Example:
if(someVariableExists)
x = false
anotherFunctionCall();
It means:
if(someVariableExists) {
x = false;
}
anotherFunctionCall();
Missing HasOwnProperty
for Object
• Example :
for(key in object) {
variable = object[key] ; // includes object properties
}
}
• Solution:
for(key in object) {
if(object.hasOwnProperty(key) {
...then do something...
}
}
Eval is Evil.
• Give Access to JavaScript Compiler.
• Debug message arising from Eval are
unsearchable.
• Eval (String Parameter) then ,
– Decrease Performance
– Huge Security Risk .
Undefined Property
• Example:
var object ={
key1 = {},
key2 = undefined
}
- Running loop for checking existence of an elements
typeof object [key1] = object,
typeof object [key2] = undefined
typeof object [key3] = undefined
• Solution:
key2 = null
Misuse of Closures
• Example:
function(a, b, c) {
var d = 10;
function test (a,b,c,d){
return a+b+c+d;
}}
• Solution:
function(a, b, c) {
var d = 10;
function test (){
return a+b+c+d;
}}
Conditional Statements
• Example:
1. If(var1 = var2 ) // Assignment
-- if (var 1 == var 2)
1. for(var i=0;i<10;i) // execute in infinite loop
-- for (var i=0;i<10;i++)
1. for (var i=0;i< Array.length;i++)
-- var arrLen = Array.length;
for(var 1=0;i<arrlen; i++)
Overwriting/Overloading
function
• Overloading : Declare function more than Once
with different arguments.
• No function overloading in JavaScript.
• Last compiled function definition is used.
• This behavior is different from other
Programming Language.
Example :
-function test (param1)
- function test (param1, param2)
Missing Parameter
• Forgot to update to function calls when new
parameter add in function.
• Example:
– function(param1, param2){}
– Add new parameter Param3
– function (param1,param2,param3){
param3 = param3 II Default Value
}
JavaScript Code
Quality Tools
• Firebug
• Firebug is an extremely popular and well-
regarded front-end debugging tool.
• Drosera
Drosera is an excellent debugging tool for
Safari and WebKit-based browsers.
• NitobiBug
NitobiBug is a browser-based JavaScript object
logger and inspector

More Related Content

What's hot

Pavel kravchenko obj c runtime
Pavel kravchenko obj c runtimePavel kravchenko obj c runtime
Pavel kravchenko obj c runtime
DneprCiklumEvents
 
Zhongl scala summary
Zhongl scala summaryZhongl scala summary
Zhongl scala summary
lunfu zhong
 
NDC 2011, C++ 프로그래머를 위한 C#
NDC 2011, C++ 프로그래머를 위한 C#NDC 2011, C++ 프로그래머를 위한 C#
NDC 2011, C++ 프로그래머를 위한 C#
tcaesvk
 
Functions and Objects in JavaScript
Functions and Objects in JavaScript Functions and Objects in JavaScript
Functions and Objects in JavaScript
Dhananjay Kumar
 

What's hot (20)

Groovy Ast Transformations (greach)
Groovy Ast Transformations (greach)Groovy Ast Transformations (greach)
Groovy Ast Transformations (greach)
 
Core Java Programming Language (JSE) : Chapter IV - Expressions and Flow Cont...
Core Java Programming Language (JSE) : Chapter IV - Expressions and Flow Cont...Core Java Programming Language (JSE) : Chapter IV - Expressions and Flow Cont...
Core Java Programming Language (JSE) : Chapter IV - Expressions and Flow Cont...
 
PVS-Studio in 2021 - Error Examples
PVS-Studio in 2021 - Error ExamplesPVS-Studio in 2021 - Error Examples
PVS-Studio in 2021 - Error Examples
 
Pavel kravchenko obj c runtime
Pavel kravchenko obj c runtimePavel kravchenko obj c runtime
Pavel kravchenko obj c runtime
 
A Re-Introduction to JavaScript
A Re-Introduction to JavaScriptA Re-Introduction to JavaScript
A Re-Introduction to JavaScript
 
Clean code
Clean codeClean code
Clean code
 
Zhongl scala summary
Zhongl scala summaryZhongl scala summary
Zhongl scala summary
 
Data Flow Modeling
Data Flow ModelingData Flow Modeling
Data Flow Modeling
 
Automatically Documenting Program Changes
Automatically Documenting Program ChangesAutomatically Documenting Program Changes
Automatically Documenting Program Changes
 
javascript objects
javascript objectsjavascript objects
javascript objects
 
TDD Training
TDD TrainingTDD Training
TDD Training
 
VHDL Behavioral Description
VHDL Behavioral DescriptionVHDL Behavioral Description
VHDL Behavioral Description
 
Solid scala
Solid scalaSolid scala
Solid scala
 
block
blockblock
block
 
NDC 2011, C++ 프로그래머를 위한 C#
NDC 2011, C++ 프로그래머를 위한 C#NDC 2011, C++ 프로그래머를 위한 C#
NDC 2011, C++ 프로그래머를 위한 C#
 
JavaScript objects and functions
JavaScript objects and functionsJavaScript objects and functions
JavaScript objects and functions
 
Functions and Objects in JavaScript
Functions and Objects in JavaScript Functions and Objects in JavaScript
Functions and Objects in JavaScript
 
DIWE - Programming with JavaScript
DIWE - Programming with JavaScriptDIWE - Programming with JavaScript
DIWE - Programming with JavaScript
 
Lecture 4.2 c++(comlete reference book)
Lecture 4.2 c++(comlete reference book)Lecture 4.2 c++(comlete reference book)
Lecture 4.2 c++(comlete reference book)
 
12. Java Exceptions and error handling
12. Java Exceptions and error handling12. Java Exceptions and error handling
12. Java Exceptions and error handling
 

Similar to JavaScript Common Mistake

JavaScript Proven Practises
JavaScript Proven PractisesJavaScript Proven Practises
JavaScript Proven Practises
Robert MacLean
 

Similar to JavaScript Common Mistake (20)

An introduction to scala
An introduction to scalaAn introduction to scala
An introduction to scala
 
Advanced JavaScript
Advanced JavaScript Advanced JavaScript
Advanced JavaScript
 
Scala for Java Developers
Scala for Java DevelopersScala for Java Developers
Scala for Java Developers
 
Java Script Workshop
Java Script WorkshopJava Script Workshop
Java Script Workshop
 
A Lifecycle Of Code Under Test by Robert Fornal
A Lifecycle Of Code Under Test by Robert FornalA Lifecycle Of Code Under Test by Robert Fornal
A Lifecycle Of Code Under Test by Robert Fornal
 
Test-Driven Development of AngularJS Applications
Test-Driven Development of AngularJS ApplicationsTest-Driven Development of AngularJS Applications
Test-Driven Development of AngularJS Applications
 
Angularjs Test Driven Development (TDD)
Angularjs Test Driven Development (TDD)Angularjs Test Driven Development (TDD)
Angularjs Test Driven Development (TDD)
 
JavaScript Proven Practises
JavaScript Proven PractisesJavaScript Proven Practises
JavaScript Proven Practises
 
CoffeeScript
CoffeeScriptCoffeeScript
CoffeeScript
 
Jug trojmiasto 2014.04.24 tricky stuff in java grammar and javac
Jug trojmiasto 2014.04.24  tricky stuff in java grammar and javacJug trojmiasto 2014.04.24  tricky stuff in java grammar and javac
Jug trojmiasto 2014.04.24 tricky stuff in java grammar and javac
 
using python module: doctest
using python module: doctestusing python module: doctest
using python module: doctest
 
Specs2
Specs2Specs2
Specs2
 
Scala introduction
Scala introductionScala introduction
Scala introduction
 
關於測試,我說的其實是......
關於測試,我說的其實是......關於測試,我說的其實是......
關於測試,我說的其實是......
 
Swift 2
Swift 2Swift 2
Swift 2
 
Art of Javascript
Art of JavascriptArt of Javascript
Art of Javascript
 
Introduction to web programming for java and c# programmers by @drpicox
Introduction to web programming for java and c# programmers by @drpicoxIntroduction to web programming for java and c# programmers by @drpicox
Introduction to web programming for java and c# programmers by @drpicox
 
Scala @ TechMeetup Edinburgh
Scala @ TechMeetup EdinburghScala @ TechMeetup Edinburgh
Scala @ TechMeetup Edinburgh
 
Awesomeness of JavaScript…almost
Awesomeness of JavaScript…almostAwesomeness of JavaScript…almost
Awesomeness of JavaScript…almost
 
Testing JavaScript with Jasmine in Rails Applications
Testing JavaScript with Jasmine in Rails Applications Testing JavaScript with Jasmine in Rails Applications
Testing JavaScript with Jasmine in Rails Applications
 

Recently uploaded

Recently uploaded (20)

Understanding Discord NSFW Servers A Guide for Responsible Users.pdf
Understanding Discord NSFW Servers A Guide for Responsible Users.pdfUnderstanding Discord NSFW Servers A Guide for Responsible Users.pdf
Understanding Discord NSFW Servers A Guide for Responsible Users.pdf
 
Automating Google Workspace (GWS) & more with Apps Script
Automating Google Workspace (GWS) & more with Apps ScriptAutomating Google Workspace (GWS) & more with Apps Script
Automating Google Workspace (GWS) & more with Apps Script
 
MINDCTI Revenue Release Quarter One 2024
MINDCTI Revenue Release Quarter One 2024MINDCTI Revenue Release Quarter One 2024
MINDCTI Revenue Release Quarter One 2024
 
Powerful Google developer tools for immediate impact! (2023-24 C)
Powerful Google developer tools for immediate impact! (2023-24 C)Powerful Google developer tools for immediate impact! (2023-24 C)
Powerful Google developer tools for immediate impact! (2023-24 C)
 
Strategies for Landing an Oracle DBA Job as a Fresher
Strategies for Landing an Oracle DBA Job as a FresherStrategies for Landing an Oracle DBA Job as a Fresher
Strategies for Landing an Oracle DBA Job as a Fresher
 
Boost PC performance: How more available memory can improve productivity
Boost PC performance: How more available memory can improve productivityBoost PC performance: How more available memory can improve productivity
Boost PC performance: How more available memory can improve productivity
 
Mastering MySQL Database Architecture: Deep Dive into MySQL Shell and MySQL R...
Mastering MySQL Database Architecture: Deep Dive into MySQL Shell and MySQL R...Mastering MySQL Database Architecture: Deep Dive into MySQL Shell and MySQL R...
Mastering MySQL Database Architecture: Deep Dive into MySQL Shell and MySQL R...
 
Top 5 Benefits OF Using Muvi Live Paywall For Live Streams
Top 5 Benefits OF Using Muvi Live Paywall For Live StreamsTop 5 Benefits OF Using Muvi Live Paywall For Live Streams
Top 5 Benefits OF Using Muvi Live Paywall For Live Streams
 
The 7 Things I Know About Cyber Security After 25 Years | April 2024
The 7 Things I Know About Cyber Security After 25 Years | April 2024The 7 Things I Know About Cyber Security After 25 Years | April 2024
The 7 Things I Know About Cyber Security After 25 Years | April 2024
 
presentation ICT roal in 21st century education
presentation ICT roal in 21st century educationpresentation ICT roal in 21st century education
presentation ICT roal in 21st century education
 
Apidays New York 2024 - The value of a flexible API Management solution for O...
Apidays New York 2024 - The value of a flexible API Management solution for O...Apidays New York 2024 - The value of a flexible API Management solution for O...
Apidays New York 2024 - The value of a flexible API Management solution for O...
 
Connector Corner: Accelerate revenue generation using UiPath API-centric busi...
Connector Corner: Accelerate revenue generation using UiPath API-centric busi...Connector Corner: Accelerate revenue generation using UiPath API-centric busi...
Connector Corner: Accelerate revenue generation using UiPath API-centric busi...
 
Bajaj Allianz Life Insurance Company - Insurer Innovation Award 2024
Bajaj Allianz Life Insurance Company - Insurer Innovation Award 2024Bajaj Allianz Life Insurance Company - Insurer Innovation Award 2024
Bajaj Allianz Life Insurance Company - Insurer Innovation Award 2024
 
Exploring the Future Potential of AI-Enabled Smartphone Processors
Exploring the Future Potential of AI-Enabled Smartphone ProcessorsExploring the Future Potential of AI-Enabled Smartphone Processors
Exploring the Future Potential of AI-Enabled Smartphone Processors
 
Axa Assurance Maroc - Insurer Innovation Award 2024
Axa Assurance Maroc - Insurer Innovation Award 2024Axa Assurance Maroc - Insurer Innovation Award 2024
Axa Assurance Maroc - Insurer Innovation Award 2024
 
Bajaj Allianz Life Insurance Company - Insurer Innovation Award 2024
Bajaj Allianz Life Insurance Company - Insurer Innovation Award 2024Bajaj Allianz Life Insurance Company - Insurer Innovation Award 2024
Bajaj Allianz Life Insurance Company - Insurer Innovation Award 2024
 
Polkadot JAM Slides - Token2049 - By Dr. Gavin Wood
Polkadot JAM Slides - Token2049 - By Dr. Gavin WoodPolkadot JAM Slides - Token2049 - By Dr. Gavin Wood
Polkadot JAM Slides - Token2049 - By Dr. Gavin Wood
 
Apidays New York 2024 - Scaling API-first by Ian Reasor and Radu Cotescu, Adobe
Apidays New York 2024 - Scaling API-first by Ian Reasor and Radu Cotescu, AdobeApidays New York 2024 - Scaling API-first by Ian Reasor and Radu Cotescu, Adobe
Apidays New York 2024 - Scaling API-first by Ian Reasor and Radu Cotescu, Adobe
 
TrustArc Webinar - Stay Ahead of US State Data Privacy Law Developments
TrustArc Webinar - Stay Ahead of US State Data Privacy Law DevelopmentsTrustArc Webinar - Stay Ahead of US State Data Privacy Law Developments
TrustArc Webinar - Stay Ahead of US State Data Privacy Law Developments
 
TrustArc Webinar - Unlock the Power of AI-Driven Data Discovery
TrustArc Webinar - Unlock the Power of AI-Driven Data DiscoveryTrustArc Webinar - Unlock the Power of AI-Driven Data Discovery
TrustArc Webinar - Unlock the Power of AI-Driven Data Discovery
 

JavaScript Common Mistake

  • 1. KNOWLEDGE TRANSFER AND SHARING (Java script Common Mistake’s)
  • 2. Syntax Error 1. Missing Semicolon (;) println(“n Welcome 1”) ; // Missing for(var i= 0 ;i<10;i++) 2. Missing curly braces ({}). for(var i= 0 ;i<10;i++){ } // Missing function test (){ } // Missing 3 . Missing Open close braces (). function test ( param1,param2 ) // Missing 4. Missing Commas (,). var a = “A’” ,b = “B” // Oops, missing ',' here! c = “C”, d = “D”;
  • 3. JavaScript Is case sensitive • JavaScript is very case sensitive. • Example : function test1(inputContext){ println( “n inputContext ”+InputContext); } inputContext is different from InputContext.
  • 4. Confusion between Concatenation and Addition 1. Println (10 +2) Type of 2 is Number – Addition -- result : 12 2. Println (10 + “2”) Type of 2 is String – Concatenation --result : 102
  • 5. Confusing single and double quotes 1. Println ('Two’); -- result is Two 2. Println ("Two's"); -- result is Two’s 3. Println ('Two's'); -- Error
  • 6. Variable without - var • JavaScript is very permissive. • It will silently declare it for you globally. • Memory Leakage. • Significantly reduce the chance of bad interactions with other applications libraries.
  • 7. Differentiate float numbers from integer numbers • Example: var myNumber = 3.5; var myResult = 3.5 + 1.0; //We use .0 to keep the result as float 1. No difference between float and integers. 2. Don’t use decimals to “convert” numbers to floats. var myNumber = 3.5; var myResult = 3.5 + 1; //Result is 4.5, as expected
  • 8. Don't Use Short Hand • Curly braces should be omitted is with one-liners. Example: if(someVariableExists) x = false anotherFunctionCall(); It means: if(someVariableExists) { x = false; } anotherFunctionCall();
  • 9. Missing HasOwnProperty for Object • Example : for(key in object) { variable = object[key] ; // includes object properties } } • Solution: for(key in object) { if(object.hasOwnProperty(key) { ...then do something... } }
  • 10. Eval is Evil. • Give Access to JavaScript Compiler. • Debug message arising from Eval are unsearchable. • Eval (String Parameter) then , – Decrease Performance – Huge Security Risk .
  • 11. Undefined Property • Example: var object ={ key1 = {}, key2 = undefined } - Running loop for checking existence of an elements typeof object [key1] = object, typeof object [key2] = undefined typeof object [key3] = undefined • Solution: key2 = null
  • 12. Misuse of Closures • Example: function(a, b, c) { var d = 10; function test (a,b,c,d){ return a+b+c+d; }} • Solution: function(a, b, c) { var d = 10; function test (){ return a+b+c+d; }}
  • 13. Conditional Statements • Example: 1. If(var1 = var2 ) // Assignment -- if (var 1 == var 2) 1. for(var i=0;i<10;i) // execute in infinite loop -- for (var i=0;i<10;i++) 1. for (var i=0;i< Array.length;i++) -- var arrLen = Array.length; for(var 1=0;i<arrlen; i++)
  • 14. Overwriting/Overloading function • Overloading : Declare function more than Once with different arguments. • No function overloading in JavaScript. • Last compiled function definition is used. • This behavior is different from other Programming Language. Example : -function test (param1) - function test (param1, param2)
  • 15. Missing Parameter • Forgot to update to function calls when new parameter add in function. • Example: – function(param1, param2){} – Add new parameter Param3 – function (param1,param2,param3){ param3 = param3 II Default Value }
  • 16. JavaScript Code Quality Tools • Firebug • Firebug is an extremely popular and well- regarded front-end debugging tool. • Drosera Drosera is an excellent debugging tool for Safari and WebKit-based browsers. • NitobiBug NitobiBug is a browser-based JavaScript object logger and inspector