javascript

Displaying 11 - 20 of 22

The Difference between JavaScript and Java

Many non-programmers and young programmers are confused by the names Java and JavaScript. In fact, JavaScript was renamed to JavaScript as an afterthought and a co-marketing campaign together with Sun (the creator of Java). But there are succinct jokes for this naming coincidence: Java and JavaScript are the same like car and carpet, or ham and hamster.

First, the similarities. On a cursory look, some of the syntax of Java and JavaScript code look alike. This is because they're somewhat descended from C (putting them in the Algol family but they are both more similar to C than...

Isomorphic JavaScript myth

Isomorphic JavaScript is the idea of writing JavaScript that can run on the server just as well as in the browser, thus your otherwise frontend-only single page app (SPA), which only makes HTML appear after some post-load requests and execution, can also render the same HTML server-side (which is how things used to work) and give something to search engines to understand. AngularJS required hacks using PhantomJS to achieve this, by running a headless browser on your server.

In theory, a full stack web developer then only needs to know one language - JavaScript. In practice, knowing...

Creating forms with callbacks in React+Redux

In React, you have some simple/dumb components which are just html and other components and maybe render some values which are passed in. It becomes a little trickier when you want to add some functionality to the component, such as form elements - inputs and buttons and submit actions. What I mean by "forms with callbacks" is that you want to execute some JavaScript and also change state in your React app, but do so without giving direct access to state to the component. Instead here's one way to do it.

  1. Draw out the HTML (don't worry about using React components yet) in JSX
  2. ...

Quick explanation of JavaScript Promises

"JavaScript Promises: reason about async events, serially chain them, reduce them. General replacement for XHR"

What is a promise? Conceptually and outside the context of code, a promise is either a willful intention of achieving a result or a promise is considered the actual result itself. EcmaScript 6 (ES6) introduces the Promises API which is currently implemented by most browsers (and Edge but not IE according to caniuse.com - but there's a polyfill for that). So a JavaScript Promise is simply an object of some callback...

Assembly language vs Bytecode vs WebAssembly vs Asm.js

Assembly

In the beginning there was a CPU. And the CPU could be loaded with data which were numbers and these magical numbers would cause the CPU to process those numbers and produce new numbers. This data which the CPU was running, the numbers fed into the computer, was machine code. And all programming of computers that's still done today ultimately ends up turning into machine code for the CPU, binary machine code being the only thing a computer can understand.

But long series of numbers, where each 256 or more unique numbers has special meaning which changes depending...

Top 5 Programming Languages to Learn in 2016

It's a new year in a world that's moving faster than ever. This means it's important to keep up to date on technology, and young people who would have not been programmers before need to learn to code. There are various lists of programming languages by popularity of demand but they are too broad to read at face value. I've seen many people fail to learn a programming language when they had nothing to apply it to and were simply learning how a language works. It's a bit like learning a foreign language by reading a dictionary. The following list are my choices (not necessarily in order)...

Developer interview: What is AngularJS and What about Angular 2?

My friend Chau is a long-time Microsoft / .Net developer who has recently switched his company's focus to single-page apps (SPAs), especially web apps built using Angular. He's preparing to use Angular 2.0 now. I asked him to explain Angular a bit.

What is Angular?

A popular (frontend web) UI framework for single page applications (SPA) from Google.

What does it replace? There are a lot of JavaScript frameworks out there nowadays, so why this one?

We started out using Knockout for 2-way binding mostly but it didn't take care of anything outside of that....

JavaScript's Symbol Type (ECMAScript 6)

JavaScript is not a strongly-typed language like many classic compiled languages. Instead, like many scripting languages, it is loosely typed and has just a few basic types: number, string, object, boolean. There are also two types which are used as values (rather than to hold varying values like numbers and strings) which are null (no value) and undefined (the initial or undefined value of a variable). JavaScript is aware of Arrays as a type of object, but is still an object and not a separate type. Objects in JavaScript take prototypical inheritence. A literal object looks like a Python...

Choosing Shell script vs Python vs Node.js vs PHP for Server-side Command Line Scripting

After decades of improvements in graphical user interfaces, the Unix command line interface still remains the most powerful way to get things done for a lot of workflows. This is due to many reasons: the difficulty of quickly and precisely moving the mouse cursor compared to the ability of touch typists to select exactly what they want (even when it's via hotkey combinations), but mainly (IMO) the expressive power of composing separate Unix commands into one pipe-separated command operating on standardized files (usually text).

It's also easy to write your own Unix commands which...

PhantomJS vs Selenium for scraping and automated testing

Now that I have a bit of experience with both PhantomJS and Selenium (for Selenium, mostly in its scripting contexts) here are some things I can share. All of this assumes we can use Selenium's WebDriver and script it to be comparable to PhantomJS because PhantomJS is a out-of-the-browser Javascript module (like Node.js) without a web UI shell like Selenium (in the case of Selenium IDE). WebDriver can be controlled from many scripting languages (and even compiled languages) like Python and even JavaScript. Assume that anything about PhantomJS also applies to CasperJS which is a wrapper for...