Habits of Highly Effective JavaScript Developers

Slides:



Advertisements
Similar presentations
Def f(n): if (n == 0): return else: print(“*”) return f(n-1) f(3)
Advertisements

Javascript Introduction Norman White Material is from w3schools.com Go there to run examples interactively.
Form Validation. Learning Objectives By the end of this lecture, you should be able to: – Describe what is meant by ‘form validation’ – Understand why.
I just met you, and 'this' is crazy, but here's my NaN, so call(me) maybe? JavaScript is so weird.
Taking JavaScript Seriously IS NOT THE WORST IDEA.
JavaScript CMPT 281. Outline Introduction to JavaScript Resources What is JavaScript? JavaScript in web pages.
Set 5: Perl and Database Connections
Jquery IS JQuery Jquery Example of mouseover event that shows a submenu when menu selected: $(‘#menu’).mouseover(function() { $(‘#submenu’).show();
Introduction to Python
Client Scripting1 Internet Systems Design. Client Scripting2 n “A scripting language is a programming language that is used to manipulate, customize,
JavaScript: The Language Andrew Miadowicz Program Manager DEV307.
Introduction to JavaScript Gordon Tian
Extending HTML CPSC 120 Principles of Computer Science April 9, 2012.
USING UNITY JAVASCRIPT. CONVENTIONS AND SYNTAX IN JAVASCRIPT Case Sensitivity All keywords like var or function must be in lowercase. All variable names,
ALBERT WAVERING BOBBY SENG. Week 4: JavaScript  Quiz  Announcements/questions.
Functions Reusable Parts of Code SoftUni Team Technical Trainers Software University
Functions and Closures. JavaScript Closures Are Everywhere In JS we often want to say “when this thing happens, do something” event driven programming.
CSE 341 Lecture 29 a JavaScript, the bad parts slides created by Marty Stepp see also: JavaScript: The Good Parts, by.
JavaScript Best Practices Learn How to Write Better Quality JavaScript Software University Technical Trainers SoftUni Team.
The Report Generator Viewing Student Outcomes. Install the Report Generator In a browser, go to Click.
Introduction to Web Frontend Development with JavaScript.
Lesson 16. Practical Application 1 We can take advantage of JavaScript and the DOM, to set up a form so that the first text box of a form automatically.
JavaScript. JavaScript Introduction JavaScript is the world's most popular programming language. It is the language for HTML and the web, for servers,
JavaScript for C# developers Dhananjay Microsoft MVP
PHP Reusing Code and Writing Functions 1. Function = a self-contained module of code that: Declares a calling interface – prototype! Performs some task.
Logical Operators.  Quiz  Let's look at the schedule  Logical Operators 2.
Python Strings. String  A String is a sequence of characters  Access characters one at a time with a bracket operator and an offset index >>> fruit.
Introduction to Javascript. What is javascript?  The most popular web scripting language in the world  Used to produce rich thin client web applications.
JavaScript Syntax Fort Collins, CO Copyright © XTR Systems, LLC Introduction to JavaScript Syntax Instructor: Joseph DiVerdi, Ph.D., MBA.
1 Agenda  Unit 7: Introduction to Programming Using JavaScript T. Jumana Abu Shmais – AOU - Riyadh.
JAVASCRIPT Dr Mohd Soperi Mohd Zahid Semester /16.
JavaScript Tutorial First lecture 19/2/2016. Javascript is a dynamic computer programming language. It is lightweight and most commonly used as a part.
JavaScript Best Practices Learn How to Write Better Quality JavaScript Software University Technical Trainers SoftUni Team.
C++ Programming Basics C++ Lecture 1 Stacy MacAllister.
Python Fundamentals: Hello World! Eric Shook Department of Geography Kent State University.
Logical Operators.  Quizzes!  Let's look at the schedule  Logical Operators 2.
JavaScript: Conditionals contd.
Basic concepts of C++ Presented by Prof. Satyajit De
Chapter 10 Programming Fundamentals with JavaScript
JavaScript: Good Practices
Learning to Program D is for Digital.
Python Let’s get started!.
CS5220 Advanced Topics in Web Programming JavaScript and jQuery
Section 13 – Using External JavaScript Modules
PHP Hypertext Preprocessor
Modern JavaScript Develop And Design
JavaScript Syntax and Semantics
HTML.
Variables, Printing and if-statements
Writing Functions( ) (Part 5)
Writing Functions( ) (Part 5)
IPC144 Introduction to Programming Using C Week 1 – Lesson 2
Chapter 10 Programming Fundamentals with JavaScript
CISC101 Reminders Assn 3 due tomorrow, 7pm.
T. Jumana Abu Shmais – AOU - Riyadh
Strings A string is a sequence of characters that is treated as a single value. Strings are objects. We have been using strings all along. Every time.
Introduction to TouchDevelop
CS5220 Advanced Topics in Web Programming JavaScript Basics
Python 21 Mr. Husch.
Testing and Repetition
CS5220 Advanced Topics in Web Programming Node.js Basics
CS3220 Web and Internet Programming JavaScript Basics
Constructors, GUI’s(Using Swing) and ActionListner
Nate Brunelle Today: Conditional Decision Statements
Javascript Chapter 19 and 20 5/3/2019.
Scoping and Hoisting Imran Rashid CTO at ManiWeber Technologies.
C++ Basics CSci 107. A C++ program //include headers; these are modules that include functions that you may use in your //program; we will almost always.
CS3220 Web and Internet Programming JavaScript Basics
Web Programming and Design
Promises.
Presentation transcript:

Habits of Highly Effective JavaScript Developers #JSHabits @jonathanfmills

This is me… Jonathan Mills Consultant at Paige Technologies I Write JavaScript Pluralsight Author… This is me…

“We are what we repeatedly do. Excellence is not an act, but a habit” Aristotle

Know Your Code

JS is…

JS is… Not your primary language

JS is…

JS is… Different

JS is…

JS is… Helpful

JS is… Helpful;

“Certain ECMAScript statements (…) must be terminated with semicolons EcmaScript Standards

“For convenience, however, such semicolons may be omitted from the source text in certain situations.“ EcmaScript Standards

“These situations are described by saying that semicolons are automatically inserted….” EcmaScript Standards

var a = 12 var b = 13 ​ if(a){console.log(a)} console.log(a+b)

var a = 12; var b = 13; ​ if(a){console.log(a);} console.log(a+b);

var a = 12 var b = 13 var c = b + a ​ ['menu', 'items', 'listed'] .forEach(function(element) { console.log(element) })

var a = 12; var b = 13; var c = b + a ​ ['menu', 'items', 'listed'] .forEach(function(element) { console.log(element); })

var a = 12 var b = 13 var c = b + a ​ (function(){ console.log('inside my iife’) console.log('doing secret stuff...’) }())

var a = 12; var b = 13; var c = b + a ​ (function(){ console.log('inside my iife'); console.log('doing secret stuff...'); }())

var a = 12; var b = 13; var c = b + a ​ ;(function(){ console.log('inside my iife'); console.log('doing secret stuff...'); }())

function returnObject() { if(someTrueThing) greeting: 'hello' } restricted productions

function returnObject() { if(someTrueThing) return; greeting: 'hello' }

Equality…

var x = 1; var y = '1'; ​ if (x == y) { document.write('Equal') } else { document.write('Not Equal') }

var x = false; var y = 0; ​ if (x == y) { document.write('Equal') } else { document.write('Not Equal') }

var x = false; var y = 0; ​ if (x === y) { document.write('Equal') } else { document.write('Not Equal') }

name:'Jon', DOB: ‘11/11/11', single: false } var person = { ​ if(person.name){ document.write('Exists') } else { document.write('Does Not ')

name:'Jon', DOB: ‘11/11/11', single: false } var person = { ​ if(person.DOB){ document.write('Exists') } else { document.write('Does Not ')

name:'Jon', DOB: ‘11/11/11', single: false } var person = { ​ if(person.single){ document.write('Exists') } else { document.write('Does Not ')

name:'Jon', DOB: ‘11/11/11', single: false } var person = { if(typeof person.name !== 'undefined'){ document.write('Exists') } else { document.write('Does Not ')

Hoisting Function Expressions Prototypes…

Spend the time to understand what is happening

Linting

Have an automated system check your code for you!

Know Your IDE

Make your IDE work for you!

Strict Mode

“JavaScript is trying to help you…. Don’t let it.” Me

Globals

var toPrint = "print me"; ​ function print(out){ var stringToPrint = 'printing: ' + out;   console.log(stringToPrint); } print('Hello');

var toPrint = "print me"; ​ function print(out){ var stringToPrint = 'printing: ' + out;   console.log(stringToPrint); } print('Hello'); console.log(stringToPrint);

var toPrint = "print me"; ​ function print(out){ var stringToPrint = 'printing: ' + out;   console.log(stringToPrint); } print('Hello'); console.log(stringToPrint); // ReferenceError:

var toPrint = "print me"; ​ function print(out){ stringToPrint = 'printing: ' + out;   console.log(stringToPrint); } print('Hello'); console.log(stringToPrint);

var toPrint = "print me"; ​ function print(out){ stringToPrint = 'printing: ' + out;   console.log(stringToPrint); } print('Hello'); console.log(stringToPrint); // printing: Hello

'use strict'; var toPrint = "print me"; ​ function print(out){ stringToPrint = 'printing: ' + out;   console.log(stringToPrint); } print('Hello'); console.log(stringToPrint);

'use strict’; var toPrint = "print me"; ​ function print(out){ stringToPrint = 'printing: ' + out; // ReferenceError   console.log(stringToPrint); } print('Hello'); console.log(stringToPrint);

Deletes…

var obj = {a: 100,           b: 200},     myVar = 10; ​ delete obj.a; ​ console.log(obj);

var obj = {a: 100,           b: 200},     myVar = 10; ​ delete obj.a; ​ console.log(obj); //{b: 200}

var obj = {a: 100,           b: 200},     myVar = 10; ​ delete obj.a; delete obj; console.log(obj);

var obj = {a: 100,           b: 200},     myVar = 10; ​ delete obj.a; delete obj; console.log(obj); //{b: 200}

var obj = {a: 100,           b: 200},     myVar = 10; ​ delete obj.a; delete myVar; console.log(obj); console.log(myVar);

var obj = {a: 100,           b: 200},     myVar = 10; ​ delete obj.a; delete myVar; console.log(obj); //{b: 200} console.log(myVar); //10

'use strict’; var obj = {a: 100,           b: 200},     myVar = 10; ​ delete obj.a; delete myVar; delete obj; console.log(obj); console.log(myVar);

'use strict’; var obj = {a: 100,           b: 200},     myVar = 10; ​ delete obj.a; delete myVar; //SyntaxError: Delete of an unqualified identifier in strict mode. delete obj; console.log(obj); console.log(myVar);

Strict Mode makes JavaScript give you your errors…

What is this?

var objA = { greeting: 'Hello', sayHi: function (name) { } ​

var objA = { greeting: 'Hello', sayHi: function (name) { document.write(this.greeting + ' ' + name) } ​

var objA = { greeting: 'Hello', sayHi: function (name) { document.write(this.greeting + ' ' + name) } ​ objA.sayHi('Jon'); // Hello Jon

var objA = { greeting: 'Hello', sayHi: function (name) { document.write(this.greeting + ' ' + name) } var objB = { greeting: 'Sup',

var objA = { greeting: 'Hello', sayHi: function (name) { document.write(this.greeting + ' ' + name) } var objB = { greeting: 'Sup', objB.sayHi = objA.sayHi objB.sayHi('Jon');

var objA = { greeting: 'Hello', sayHi: function (name) { document.write(this.greeting + ' ' + name) } var objB = { greeting: 'Sup', objB.sayHi = objA.sayHi objB.sayHi('Jon'); // Sup Jon

var objA = { greeting: 'Hello', sayHi: function (name) { document.write(this.greeting + ' ' + name) } var objB = { greeting: 'Sup', objB.sayHi = objA.sayHi objB.sayHi('Jon'); // Sup Jon

var objA = { greeting: 'Hello', sayHi: function (name) { document.write(this.greeting + ' ' + name) } var sayHi = objA.sayHi sayHi('Jon');

var objA = { greeting: 'Hello', sayHi: function (name) { document.write(this.greeting + ' ' + name) } var sayHi = objA.sayHi sayHi('Jon'); // undefined Jon

'use strict’; var objA = { greeting: 'Hello', sayHi: function (name) { document.write(this.greeting + ' ' + name) } var sayHi = objA.sayHi sayHi('Jon'); // Ref Error

var objA = { greeting: 'Hello', sayHiAsync: function (name) { setTimeout(function () { document.write(this.greeting + ' ' + name) }, 500) } ​ objA.sayHiAsync('Jon');

Make JavaScript give you your errors

Know Who Your Functions Are…

asyncMethod('Open DB Connection', function () { //do stuff then: asyncMethod('Find User', function () { asyncMethod('validate User', function () { asyncMethod('do stuff', function(){ //do stuff }) } )

var findAndValidateUser = function(){ asyncMethod('findUser',validateUser) } var validateUser = function () { asyncMethod('validateUser',  doStuff) var doStuff = function () { asyncMethod('do stuff', function () {}) asyncMethod('Open DB Connection',findAndValidateUser)

I Promise!

function asyncMethod(message) { return new Promise(function (fulfill, reject) { setTimeout(function () { console.log(message); fulfill(); }, 500) }); }

function findUser() { return asyncMethod('Find User') } function validateUser() { return asyncMethod('validate User') function doStuff() { return asyncMethod('do stuff') asyncMethod('Open DB Connection') .then(findUser) .then(validateUser) .then(doStuff) .then(function () {})

Don’t give in to lazy callback practices

ES6 Rocks! https://kangax.github.io/compat-table/es6/

Use the latest features that are available to you

Don’t reinvent the wheel

Moment React Lodash Bootstrap Font Awesome… Underscore Angular Jquery

Use packages that are available to you.

Don’t Over Do It…

module.exports = xxxxx; function xxxxx(str, len, ch) { str = String(str); var i = -1; if (!ch && ch !== 0) ch = ' '; len = len - str.length; while (++i < len) { str = ch + str; } return str;

Habits of Highly Effective JavaScript Developers #JSHabits @jonathanfmills