Not so long ago Microsoft announced a new language trageting on front-end developers. Everybody's reaction was like: Why?!! Is it just Microsoft darting back to Google?!
So, why a new language? JavaScript has its bad parts. Mostly you can avoid them or workaraund. You can emulate class-based OOP style, modules, scoping and even run-time typing. But that is doomed to be clumsy. That's not in the language design. Google has pointed out these flaws, provided a new language and failed. Will the story of TypeScript be any different?
Not so long ago Microsoft announced a new language trageting on front-end developers. Everybody's reaction was like: Why?!! Is it just Microsoft darting back to Google?!
So, why a new language? JavaScript has its bad parts. Mostly you can avoid them or workaraund. You can emulate class-based OOP style, modules, scoping and even run-time typing. But that is doomed to be clumsy. That's not in the language design. Google has pointed out these flaws, provided a new language and failed. Will the story of TypeScript be any different?
Presented at Web Unleashed on September 16-17, 2015 in Toronto, Canada
More info at www.fitc.ca/webu
Why TypeScript?
with Jeff Francis
OVERVIEW
TypeScript is a type-checked superset of JavaScript that benefits medium-sized to complex JavaScript projects. Why would you want to learn a new language, instead of another JavaScript framework? You have all this existing JavaScript code, so how can you adopt something new without throwing the old stuff out?
This session is about the benefits of using TypeScript on top of JavaScript in your projects, and demonstrate step by step ways of migrating an existing JavaScript project to TypeScript. We will dive into code generated by the compiler and look at resources and tools that make working in TypeScript a pleasurable experience.
OBJECTIVE
To understand when it’s a good idea to use TypeScript.
TARGET AUDIENCE
JavaScript developers.
ASSUMED AUDIENCE KNOWLEDGE
Intermediate JavaScript experience.
FIVE THINGS AUDIENCE MEMBERS WILL LEARN
The basics of TypeScript – types, classes, modules, and functions
How TypeScript’s design makes getting started simple and helps projects
What compiled TypeScript looks like and how to debug
What tools can help take advantage of TypeScript’s type information
How to migrate a JavaScript project to TypeScript
An invited talk by Xavier Leroy explaining the current state of OCaml at the OCaml Users and Developers Workshop 2014. http://ocaml.org/meetings/ocaml/2014/
Even nowadays, PHP code is mostly manually audited. Expert pore over actual code, in search for bugs or code smells. Actually, it is possible to have PHP do this work itself ! Strengthened with the internal Tokenizer, bolstered by the manual, it is able to scan thousands of lines of code, without getting bored, and bringing pragmatic pieces of wisdom: official manual recommendations, version migration, code pruning and security. In the end, it deliver a global overview of the code, without reading it.
Java 8 helps use write better looking code. Checked exceptions, however, do not. What can we do to overcome these issues?
Lambdas and streams help us write clear and concise code, but can we do better? Javaslang helps out a bit.
Want more? Maybe turn to Scala.
The presentation helps us in understanding the different concepts associated with TypeScript. What is TypeScript? Why is TypeScript used and the different applications of TypeScript. For more information you can simply visit: http://mobile.folio3.com/
Presented at Web Unleashed on September 16-17, 2015 in Toronto, Canada
More info at www.fitc.ca/webu
Why TypeScript?
with Jeff Francis
OVERVIEW
TypeScript is a type-checked superset of JavaScript that benefits medium-sized to complex JavaScript projects. Why would you want to learn a new language, instead of another JavaScript framework? You have all this existing JavaScript code, so how can you adopt something new without throwing the old stuff out?
This session is about the benefits of using TypeScript on top of JavaScript in your projects, and demonstrate step by step ways of migrating an existing JavaScript project to TypeScript. We will dive into code generated by the compiler and look at resources and tools that make working in TypeScript a pleasurable experience.
OBJECTIVE
To understand when it’s a good idea to use TypeScript.
TARGET AUDIENCE
JavaScript developers.
ASSUMED AUDIENCE KNOWLEDGE
Intermediate JavaScript experience.
FIVE THINGS AUDIENCE MEMBERS WILL LEARN
The basics of TypeScript – types, classes, modules, and functions
How TypeScript’s design makes getting started simple and helps projects
What compiled TypeScript looks like and how to debug
What tools can help take advantage of TypeScript’s type information
How to migrate a JavaScript project to TypeScript
An invited talk by Xavier Leroy explaining the current state of OCaml at the OCaml Users and Developers Workshop 2014. http://ocaml.org/meetings/ocaml/2014/
Even nowadays, PHP code is mostly manually audited. Expert pore over actual code, in search for bugs or code smells. Actually, it is possible to have PHP do this work itself ! Strengthened with the internal Tokenizer, bolstered by the manual, it is able to scan thousands of lines of code, without getting bored, and bringing pragmatic pieces of wisdom: official manual recommendations, version migration, code pruning and security. In the end, it deliver a global overview of the code, without reading it.
Java 8 helps use write better looking code. Checked exceptions, however, do not. What can we do to overcome these issues?
Lambdas and streams help us write clear and concise code, but can we do better? Javaslang helps out a bit.
Want more? Maybe turn to Scala.
The presentation helps us in understanding the different concepts associated with TypeScript. What is TypeScript? Why is TypeScript used and the different applications of TypeScript. For more information you can simply visit: http://mobile.folio3.com/
Things that every JavaScript developer should know by Rachel Appel at FrontCo...DevClub_lv
JavaScript can be a passive-aggressive and fickle language that can frustrate you at every turn. It lets you do things like declare variables anywhere, but doesn’t tell you that it will hoist them while you’re not looking. Learn how JavaScript organizes data by using key-based dictionaries and how it handles functions behind the scenes. Additionally, you'll learn how JavaScript uses arrow functions, closures, prototypes and inheritance, equality, and more.
In this session, you'll learn little known facts about JavaScript, as well as frequently experienced JavaScript headaches and mistakes, and ways to avoid them. Learn these key facets of JavaScript and take your knowledge to the next level!
We <3 .rb
but - still .rb < perfect
This presentation shows some of the ways that this language, engineered for maximum programmer happiness and least surprise, can still have some nasty gotchas.
Introduction to web programming for java and c# programmers by @drpicoxDavid Rodenas
(better presented by @drpicox)
Slides of an introductory course for web programming focusing in basic Javascript and CSS concepts. It assumes knowledge of programming, Java or C#.
Making JavaScript Libraries More ApproachablePamela Fox
A talk given at NotConf in Phoenix, Texas in 2012.
(Alternative title: Why nested ternary operators make me want to kick inanimate objects in the nuts.)
Dan Shappir "JavaScript Riddles For Fun And Profit"Fwdays
You consider yourself a JavaScript expert. Your colleagues come to you whenever they're unsure about a JavaScript feature. But how good are you really? During this session you will find out. I will pose a series of ever more challenging JavaScript riddles and brain-teasers. We'll see how far you are able to go, and along the way you'll likely learn some new things about this ever-evolving language.
We <3> true
But - still .rb < perfect # => true
Though Ruby was allegedly "engineered to maximize programmer happiness", in part by adhering to the "principle of least surprise", Ruby still has some surprising and annoying gotchas. This presention contains an Array, er, a bunch of them, from programming-newbie gotchas to ones that still "get" grizzled veteran Rubyists. The talk these are from, approximately 45 minutes, may save you many hours of frustrated head-scratching (and bashing against the desk) later!
Similar to I just met you, and "this" is crazy, but here's my NaN, so call(me), maybe? by Rachel Appel (20)
Dev Dives: Train smarter, not harder – active learning and UiPath LLMs for do...UiPathCommunity
💥 Speed, accuracy, and scaling – discover the superpowers of GenAI in action with UiPath Document Understanding and Communications Mining™:
See how to accelerate model training and optimize model performance with active learning
Learn about the latest enhancements to out-of-the-box document processing – with little to no training required
Get an exclusive demo of the new family of UiPath LLMs – GenAI models specialized for processing different types of documents and messages
This is a hands-on session specifically designed for automation developers and AI enthusiasts seeking to enhance their knowledge in leveraging the latest intelligent document processing capabilities offered by UiPath.
Speakers:
👨🏫 Andras Palfi, Senior Product Manager, UiPath
👩🏫 Lenka Dulovicova, Product Program Manager, UiPath
LF Energy Webinar: Electrical Grid Modelling and Simulation Through PowSyBl -...DanBrown980551
Do you want to learn how to model and simulate an electrical network from scratch in under an hour?
Then welcome to this PowSyBl workshop, hosted by Rte, the French Transmission System Operator (TSO)!
During the webinar, you will discover the PowSyBl ecosystem as well as handle and study an electrical network through an interactive Python notebook.
PowSyBl is an open source project hosted by LF Energy, which offers a comprehensive set of features for electrical grid modelling and simulation. Among other advanced features, PowSyBl provides:
- A fully editable and extendable library for grid component modelling;
- Visualization tools to display your network;
- Grid simulation tools, such as power flows, security analyses (with or without remedial actions) and sensitivity analyses;
The framework is mostly written in Java, with a Python binding so that Python developers can access PowSyBl functionalities as well.
What you will learn during the webinar:
- For beginners: discover PowSyBl's functionalities through a quick general presentation and the notebook, without needing any expert coding skills;
- For advanced developers: master the skills to efficiently apply PowSyBl functionalities to your real-world scenarios.
GDG Cloud Southlake #33: Boule & Rebala: Effective AppSec in SDLC using Deplo...James Anderson
Effective Application Security in Software Delivery lifecycle using Deployment Firewall and DBOM
The modern software delivery process (or the CI/CD process) includes many tools, distributed teams, open-source code, and cloud platforms. Constant focus on speed to release software to market, along with the traditional slow and manual security checks has caused gaps in continuous security as an important piece in the software supply chain. Today organizations feel more susceptible to external and internal cyber threats due to the vast attack surface in their applications supply chain and the lack of end-to-end governance and risk management.
The software team must secure its software delivery process to avoid vulnerability and security breaches. This needs to be achieved with existing tool chains and without extensive rework of the delivery processes. This talk will present strategies and techniques for providing visibility into the true risk of the existing vulnerabilities, preventing the introduction of security issues in the software, resolving vulnerabilities in production environments quickly, and capturing the deployment bill of materials (DBOM).
Speakers:
Bob Boule
Robert Boule is a technology enthusiast with PASSION for technology and making things work along with a knack for helping others understand how things work. He comes with around 20 years of solution engineering experience in application security, software continuous delivery, and SaaS platforms. He is known for his dynamic presentations in CI/CD and application security integrated in software delivery lifecycle.
Gopinath Rebala
Gopinath Rebala is the CTO of OpsMx, where he has overall responsibility for the machine learning and data processing architectures for Secure Software Delivery. Gopi also has a strong connection with our customers, leading design and architecture for strategic implementations. Gopi is a frequent speaker and well-known leader in continuous delivery and integrating security into software delivery.
JMeter webinar - integration with InfluxDB and GrafanaRTTS
Watch this recorded webinar about real-time monitoring of application performance. See how to integrate Apache JMeter, the open-source leader in performance testing, with InfluxDB, the open-source time-series database, and Grafana, the open-source analytics and visualization application.
In this webinar, we will review the benefits of leveraging InfluxDB and Grafana when executing load tests and demonstrate how these tools are used to visualize performance metrics.
Length: 30 minutes
Session Overview
-------------------------------------------
During this webinar, we will cover the following topics while demonstrating the integrations of JMeter, InfluxDB and Grafana:
- What out-of-the-box solutions are available for real-time monitoring JMeter tests?
- What are the benefits of integrating InfluxDB and Grafana into the load testing stack?
- Which features are provided by Grafana?
- Demonstration of InfluxDB and Grafana using a practice web application
To view the webinar recording, go to:
https://www.rttsweb.com/jmeter-integration-webinar
Neuro-symbolic is not enough, we need neuro-*semantic*Frank van Harmelen
Neuro-symbolic (NeSy) AI is on the rise. However, simply machine learning on just any symbolic structure is not sufficient to really harvest the gains of NeSy. These will only be gained when the symbolic structures have an actual semantics. I give an operational definition of semantics as “predictable inference”.
All of this illustrated with link prediction over knowledge graphs, but the argument is general.
Builder.ai Founder Sachin Dev Duggal's Strategic Approach to Create an Innova...Ramesh Iyer
In today's fast-changing business world, Companies that adapt and embrace new ideas often need help to keep up with the competition. However, fostering a culture of innovation takes much work. It takes vision, leadership and willingness to take risks in the right proportion. Sachin Dev Duggal, co-founder of Builder.ai, has perfected the art of this balance, creating a company culture where creativity and growth are nurtured at each stage.
Connector Corner: Automate dynamic content and events by pushing a buttonDianaGray10
Here is something new! In our next Connector Corner webinar, we will demonstrate how you can use a single workflow to:
Create a campaign using Mailchimp with merge tags/fields
Send an interactive Slack channel message (using buttons)
Have the message received by managers and peers along with a test email for review
But there’s more:
In a second workflow supporting the same use case, you’ll see:
Your campaign sent to target colleagues for approval
If the “Approve” button is clicked, a Jira/Zendesk ticket is created for the marketing design team
But—if the “Reject” button is pushed, colleagues will be alerted via Slack message
Join us to learn more about this new, human-in-the-loop capability, brought to you by Integration Service connectors.
And...
Speakers:
Akshay Agnihotri, Product Manager
Charlie Greenberg, Host
Encryption in Microsoft 365 - ExpertsLive Netherlands 2024Albert Hoitingh
In this session I delve into the encryption technology used in Microsoft 365 and Microsoft Purview. Including the concepts of Customer Key and Double Key Encryption.
Transcript: Selling digital books in 2024: Insights from industry leaders - T...BookNet Canada
The publishing industry has been selling digital audiobooks and ebooks for over a decade and has found its groove. What’s changed? What has stayed the same? Where do we go from here? Join a group of leading sales peers from across the industry for a conversation about the lessons learned since the popularization of digital books, best practices, digital book supply chain management, and more.
Link to video recording: https://bnctechforum.ca/sessions/selling-digital-books-in-2024-insights-from-industry-leaders/
Presented by BookNet Canada on May 28, 2024, with support from the Department of Canadian Heritage.
State of ICS and IoT Cyber Threat Landscape Report 2024 previewPrayukth K V
The IoT and OT threat landscape report has been prepared by the Threat Research Team at Sectrio using data from Sectrio, cyber threat intelligence farming facilities spread across over 85 cities around the world. In addition, Sectrio also runs AI-based advanced threat and payload engagement facilities that serve as sinks to attract and engage sophisticated threat actors, and newer malware including new variants and latent threats that are at an earlier stage of development.
The latest edition of the OT/ICS and IoT security Threat Landscape Report 2024 also covers:
State of global ICS asset and network exposure
Sectoral targets and attacks as well as the cost of ransom
Global APT activity, AI usage, actor and tactic profiles, and implications
Rise in volumes of AI-powered cyberattacks
Major cyber events in 2024
Malware and malicious payload trends
Cyberattack types and targets
Vulnerability exploit attempts on CVEs
Attacks on counties – USA
Expansion of bot farms – how, where, and why
In-depth analysis of the cyber threat landscape across North America, South America, Europe, APAC, and the Middle East
Why are attacks on smart factories rising?
Cyber risk predictions
Axis of attacks – Europe
Systemic attacks in the Middle East
Download the full report from here:
https://sectrio.com/resources/ot-threat-landscape-reports/sectrio-releases-ot-ics-and-iot-security-threat-landscape-report-2024/
I just met you, and "this" is crazy, but here's my NaN, so call(me), maybe? by Rachel Appel
1. I just met you, and 'this' is crazy,
but here's my NaN, so call(me)
maybe?
JavaScript is so weird
2. What makes JavaScript fun?
(and by fun I mean....a little bit strange)
• Eval
• parseInt
• NaN
• With
• JSLint/JSHint
• Arrays
• Switches
• more...
• JavaScript
• Blocks
• Functions
• Null
• Equality
• Truthy/Falsey
• Objects
• this!
6. Syntax Error
• Most often, a newline (n) ends a statement unless...
• The statement has an unclosed parenthesis ")", array literal, or object literal.
• The line uses -- or ++
• Any block statements such as for, while, do, if, or else, and there is no starting
bracket "{"
• After these constructs: break, continue, return, throw
7. Just say no to single line blocks
One single line
if (ok)
x = true;
Then looks like
(to the dev)
if (ok)
x = true;
callFunc();
Devs turn into
if (ok)
x = true;
callFunc();
In reality it is
(to the parser)
if (ok) {
x = true;
}
callFunc();
8. Putting the "fun" in functions
function functionStatement() {
// Some code
return value;
}
var functionExpression = function() {
// Some code
return value;
};
9. Putting the "fun" in functions
(function () {
console.log("anonymous function");
})();
(function IIFE() {
console.log("function expression");
})();
10. Putting the "fun" in functions
function main() {
functionStatement();
function functionStatement() { ... }
// oh noes! this won't work
functionExpression();
var functionExpression = function() { ... }
}
12. Arrays
• There is no such thing
• No dimensions
• No out of bounds errors
• typeof doesn't know the difference
13. Carry on
• continue statement
"I've never seen a piece of code that was not improved by
removing it"
-- Crockford
14. The switch
• Auto fallthrough switch (expression) {
case expression:
statements
[break;]
case expression:
statements
[break;]
default:
statements
[break;]
}
15. Let's get to the truth of the matter
Truthy values
'false' (quoted false)
'0' (quoted zero)
() (empty functions)
[] (empty arrays)
{} (empty objects)
All other values
Falsey values
false
0 (zero)
'' (empty string)
null
undefined
NaN
19. Eval - the most evil of all?
Or just a lowly, misunderstood, function?
var x = eval("forms[0].option" + optionNumber + ".checked");
var x = forms[0]["option" + optionNumber].checked;
20. Are you with me, or against me?
with (objX) {
// statements
}
21. New, new, don't do
• typed wrappers
• new object
• new array
• new Date
23. parseInt's farce parsing
0X or 0x 16 (hexadecimal)
0 10 (decimal)
8 (octal)
Everything else 10 (decimal)
var result = parseInt(numericString, 10);
24. NaN
• It claims it's NotANumber, but it's a number.
• Don't use equality operators with NaN
• Use Number.isNaN() instead
• Use typeof instead
• Don't use plain isNaN() – or else nothing is a number!
• ES6 Number.isNaN()
25. Seems legit
var add = function() {
return arguments[0] + arguments[1];
Is legit
function(where are the arguments?) {
};
console.log(add(4, 4)); // returns 8
26. How to avoid all the odd stuff
• JSLint
• JSHint
• JSFiddle
Editor's Notes
Image Source http://i.imgur.com/wR3ZxfB.jpg
Sometimes JS treats a function like a value and sometimes it treats it as an executable block of code. This is why we have both functions statement and function expression. Let's dig into each:
-The function statement
Syntactically the function statement starts with the function keyword then names the function end encloses the function contents with brackets.
Use a function statement to declare a function that you will use later. The code in between the brackets will not execute until the function is called from somewhere else. Inside of a function statement we use the return keyword to return a value to the calling code. Functions statements load at parse time before any code is executed.
Function expressions, on the other hand, loads when the interpreter reaches that line of code. – that means they load at runtime.
So if you try to call a function expression before it's loaded, you'll get an error. But if you call a function declaration, it'll always work. Because no code can be called until all declarations are loaded.
Function expressions run immediately, and when they do it's called an IIFE or Immediately-Invoked Function Expression
An Immediately-Invoked Function Expression is the only function that you can't call, it simply executes on the spot as the interpreter hits its location in code.
What makes the function execute immediately is the syntactic location of empty parenthesis just after the function's closing curly bracket.
You have flexibility in choosing the calling syntax, depending on whether or not you plan on using the return value. Regardless, it is the loading behavior that is more important than the syntax. In the on screen sample, we see how the code will work, but we should investigate the mechanics of how function statements and expressions work. [demo]
Let's see JavaScript run some functions and determine the difference in loading between statements and expressions.
As you can see here in the demo, we have a web page in IE on the left and the IE debug tools on the right.
The developer tools show an html page containing a single button that runs some script.
In its corresponding JS file we see the declarations for all 3 function types starting with a
function statement the top of the file that returns a string into a variable named "s" in the calling code.
The function expression does the same by returning a string with the value "function expression" in it, and it returns that value into a variable named "e". In this case we are using both the function statement and expression the same way.
These two functions sit alongside an IIFE, which does not return any value as its job is to run the code immediately.
let's create a breakpoint, and see these dynamics in action. But before we do, let's take note that the call to the function expression happens before its location so that should error. I'll hit F5 now.
As you can see, the code doesn't even make it to the break point.
The function statement runs as you'd expect. The expression does not. This is because its trying to call the function expression before it loads, and expressions load where they are located in code – so it's not loaded yet.
If we swap the call and declaration of the function expression, then it should work.
Let's try running the code again.
We see it makes it to the breakpoint, so we know the expression has worked. Let's continue running and take a look at the IE output console, we can see that all three functions run, including the IIFE that ran with no need to call it.
Arrays in JS aren't real arrays, they're phony
no dimenstions
no out of bounds errors
What constitutes something falsy in JS?
false.
0 (zero)
"" (empty string)
null
undefined
NaN (a special Number value meaning "Not a Number")
All other values are truthy, including "0" (zero in quotes), "false" (false in quotes), empty functions, empty arrays, and empty objects.
Falsey:
false
0 (zero)
"" (empty string)
null
undefined
NaN
Truthy
"false" (false in quotes)
"0" (zero in quotes)
() (empty functions)
[] (empty arrays)
{} (empty objects)
All other values
What constitutes something falsy in JS?
false.
0 (zero)
"" (empty string)
null
undefined
NaN (a special Number value meaning "Not a Number")
All other values are truthy, including "0" (zero in quotes), "false" (false in quotes), empty functions, empty arrays, and empty objects.
JavaScript has two sets of equality operators, equal to (==) and exactly equal to (===) and their counterparts in negation (!= and !==). The exactly equals works the way you expect. If the two operands are of the same type and have the same value, then exactly equals produces true and its negative partner (!==) produces false. The plain equals, OTOH, see different data types and attempts to coerce the values (it's called type coercion) by using a set of many overly complex rules.
It's just not reasonable to memorize all these rules, especially if you are trying to create team standards from them. Therefore, since it's more accurate going with the exactly equals is the best option.
Let's see some of this JS equality or non equality as the case may be, in action...[demo]
THE TAKE AWAY: Use the === and !== opeartors as they give consistent and accurate results, more closely to what you might expect.
console.log(0 == '');
console.log(0 === '');
console.log(0 == '0');
console.log(0 === '0');
console.log(false == 'false');
console.log(false === 'false');
console.log(false == '0');
console.log(false === '0');
console.log(false == undefined);
console.log(false === undefined);
console.log(false == null);
console.log(false === null);
console.log(null == undefined);
console.log(null === undefined);
console.log('\t\r\n' == 0);
console.log('\t\r\n' === 0);
Let's look at how JavaScript compares some values with both the standard equality operator and the exactly equals operator.
I'll paste in some expressions that log their output
First, does 0 == '' (zero = empty string). The equality operator says yes and exactly equals says no. **
0 == '0' // true (zero and quoted zero, that's ) Again, The equality operator says yes and exactly equals says no.
false == 'false' // false (does false = a quoted false) That's a result of false on both lines of code,
false == '0' // true (does false = quoted zero) That's conflicting results between the operators
false == undefined is in agreement between them as is false == null
But null == undefined is true for equals but false for exactly equals, and the oddest of all, ' \t\r\n ' == 0 // true (tab, carriage return, new line) DOES equal zero, sometimes. But not really.
(reverse operands and try ===) **
Many folks try to treat "this" the same way that it works in other languages and their notion of this is normally static and at the class level. JavaScript is different though, as this works based on the context of the calling code.
Usually this belongs to the window, or global object, but it can also be the HTML element that has caused an event, for example, a button causing a click event. Then the function is owned by that source element and that element becomes this.
To go a little deeper
JavaScript functions run in an execution context that goes on the stack. The stack is an in memory storage location for variables and data.
Functions are also values, and they're treated like objects/values.
What this means is that each time another function runs, it gets pushed onto the stack and the context for "this" changes. That's unlike other languages where this is usually clearly defined.
So the value of this depends on 2 things: What kind of code is executing? (global, function, or eval) and the calling code.
*******
ES5 introduces the a way that you can set the value of "this" in a function, as the first argument of the call.
Here in the IE console we have a function called saySomething that accepts a string and logs both this and the string to form a sentence about what this . Let's see it work.
Now that I've run the function I can call it and make 'this' a programmer or a trekkie or katniss everdeen. Not that you'd wants strings to be this bit
function saySomething(thing) {
console.log(this + " says " + thing);
}
saySomething.call("A programmer", "Hello world");
saySomething.call("A Trekkie", "Live long and prosper.");
saySomething.call("Katniss Everdeen", "May the odds be ever in your favor");
saySomething.call("A ghost", "Boooooooo!");
JavaScript contains a function named eval that allows you to run dynamic snippets of code. While this sounds like a great idea, it can introduce some nasty security bugs, as malicious users can try to insert and run malicious code.
The thing is - there's usually a better, clearer, and easier way than resorting to eval. When folks use eval it is usually because they are unaware that there is a perfectly fine alternative in JS already.
For example, something like this (1st bullet) where eval ties a dropdown's option to
Since you're executing dynamic code created at runtime, it's going to be slower than regular JS parsing.
Debugging is a challenge
Most often, programmers use eval to parse string numerals to array subscripts
--Can be changed to—
function isChecked(optionNumber) } var result = isChecked(1);
FRIENDS OF EVAL – settimeout new function
Just like in VB, JS has a with statement. This statement allows you to block off some code to work directly with variables using a shortened syntax. While this seems like a feature it usually ends up confusing developer rather than helping. For one, it's sporadic and inconsistent usage makes it difficult as it rarely adheres to any company or teams coding standards.
parseInt is a function that accepts a string and parses it to ensure it is an integer. It has two method signatures, one which accepts only the string to convert, and the next accepts a string and a radix, or base, such as base 2, or base 10. Most software runs perfectly fine in base 10 systems and we normally don't need to specify that as the default. However, parseInt doesn't rely on what the system defaults are to perform its duty. Rather, parseInt assumes the radix based on the following rules: [next slide]
If the input string begins with "0x" or "0X", radix is 16 (hexadecimal) and the remainder of the string is parsed.
If the input string begins with "0", the radix could be octal or decimal. The radix that parseInt uses is dependent on external factors like whether or not the browser supports it based on its ES5 implementation.
If the input string begins with any other value, the radix is 10 (decimal).
Your choice is to try to memorize all these facts or, just make it a rule that you specify a radix when using parseInt. The syntax will look something like this [show sample] It seems the latter is far easier to remember, code, and maintain.
As an example of parseInt's craziness, let's examine a sample from the Mozilla Developer center of 15 different calls
https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/parseInt
parseInt("2A",16);
parseInt("2A", 8);
---
parseInt("2A",16); // 42
parseInt("2A", 10); // 2
parseInt("2A", 8); // 2
parseInt(42.99, 10); // 42
---
from Mozilla
parseInt(" 0xF", 16);
parseInt(" F", 16);
parseInt("17", 8);
parseInt(021, 8);
parseInt("015", 10);
parseInt(15.99, 10);
parseInt("FXX123", 16);
parseInt("1111", 2);
parseInt("15*3", 10);
parseInt("15e2", 10);
parseInt("15px", 10);
parseInt("12", 13);
console.log(parseInt(" 0xF", 16));
console.log(parseInt(" F", 16));
console.log(parseInt("17", 8));
console.log(parseInt(021, 8));
console.log(parseInt("015", 10));
console.log(parseInt(15.99, 10));
console.log(parseInt("FXX123", 16));
console.log(parseInt("1111", 2));
console.log(parseInt("15*3", 10));
console.log(parseInt("15e2", 10));
console.log(parseInt("15px", 10));
console.log(parseInt("12", 13));
typeof NaN returns 'number'
the lolz with that one
With all these crazy things that JS does, we need to ensure our code actually works! As you've learned, JS has enough rules that memorizing them is a daunting task. That's no problem though, as we have tools to help us verify (or lint), our code.
JSFiddle – Of course I've been using this throughout the course. JSFiddle as you know is an online playground that lets you work with html, css, and js, of course, all online. What we didn't talk about is that can save code and perform some linting with JSHint to test out again later.
JSLint – This is another online utility by Douglas Crockford (author of a famous JS book called "Javascript The good parts")
JSHint – JSLint is quite sharp and stricts, so JSHint is a lightweight version of JSLint.
Of course if you develop software for a company you might use Visual Studio that has linting options and tools, as well as Jet Brain's editor named Web Storm.
No longer will you be stuck when JavaScript decides to misbehave.
You've learned that Javascript has many quirks from simply annoying to downright nasty. To make sure that JavaScript is used correctly and effectively by your team, balance their styles and skills against the many gotchas you've learned here. Just as well you can use JSLint and JSHint to your advantage to assist you in writing better code!