Welcome!

@DevOpsSummit Authors: Pat Romanski, Elizabeth White, Yeshim Deniz, Liz McMillan, Zakia Bouachraoui

Related Topics: @DevOpsSummit, Microservices Expo, @ThingsExpo

@DevOpsSummit: Blog Feed Post

Node.js ABC’s - J is for JavaScript By @JoePruitt | @DevOpsSummit #IoT #API #DevOps #Microservices

JavaScript is primarily a client-based dynamic scripting language most commonly used within web browsers

Node.js is an open source runtime environment for server-side and network based applications.  At it's core, Node.js uses the Google V8 JavaScript engine to execute client code and a large portion of the core basic modules are written in JavaScript.  Since, for all practical purposes, writing Node.js applications is writing JavaScript applications, it makes sense to try to understand the gist of what JavaScript is.

What is JavaScript

JavaScript is primarily a client-based dynamic scripting language most commonly used within web browsers as client-side scripts to interact with the user, browser, and communicate asynchronously to servers.

If you have been part of any web-based development, odds are you have worked with JavaScript in one form or another.  In this article, I'll focus on the aspects of JavaScript that are relevant within the Node.js environment.

Types

js

Node.js has only a few core object types including boolean, number, object, and string.  There are three complex types consisting of the array, function, and object.  And, finally, null and undefined are special objects that are treated in their own way.
> typeof 10;
'number'
> typeof "HI";
'string'
> typeof function() { }
'function

Constants

While Node.js does support the const keyword, is it not widely used.  A standard practice is to use all upperscore characters when defining a constant.

> var HOURS_PER_DAY = 24;

Numbers

All numbers in JavaScript are 64-bit 754 double-precision floating-point numbers.  For numbers that can be expressed in 2&53 bits, their type behaves much like an integer in any other language.

> 100
100
> 1/3
0.3333333333333333

There are functions that can help you convert strings to numbers

> parseInt("12345")
12345
> parseFloat("1.2345")
1.2345
> parseInt("1.2345")
1

Booleans

The boolean type can have values of true or false.  false, 0, empty strings, NaN, null, and undefined all evaluate to false and all other values evaluate to true.

Strings

Strings are sequences of Unicode characters that can be wrapped in single or double quote characters. The string type has built-in properties such as "length" to give you access to attributes about the string

> var s = "hi there"
> s
'hi there'
> s.length
8

Objects

JavaScript resolves around objects and are something you will use in virtually any JavaScript-based coding effort.  They are extensible allowing you to add and remove properties and methods.  To create an Object, you can use the new keyword or use the preferred object literal syntax

> var o = new Object();
undefined
> var o = {};
undefined

One of the benefits of Object-Literal syntax is that you can specify the contents of an object at initialization time

> var person = {
  first_name: "Joe",
  last_name: "Pruitt"
};

You can also add a new property to an object like this

> person.weight = 180;
180
> person['weight'] = 180;
180
> user
{ first_name: 'Joe',
  last_name: 'Pruitt',
  weight: 180 }

To delete an object or property, you can use the keyword:

> delete user.weight
true
> user
{ first_name: 'Joe',
  last_name: 'Pruitt' }

Arrays

The array type is a special implementation of the object type.  To create arrays, you can use the traditional notation, or the array-literal syntax

> var a1 = new Array();
undefined
> a1
[]
> var a2 = [];
undefined
> a2
[]

To add an item to an array, you can do one of the following

> var a = []
undefined
> a.push("hi")
1
> a
[ 'hi' ]
> a[a.length] = "there";
'there'
> a
[ 'hi', 'there' ]

Functions

JavaScript is a functional programming language in that functions are fully typed objects and can be extended, manipulated, and used as data.

A simple function is defined with the function keyword

> function hi(name) {
  console.log("Hey " + name + "!");
}
> hi("Joe");
Hey Joe!

Parameters are declared in the parameter list after the function name.  If too few parameters are passed in, the missing ones will be undefined.  If too many parameters are passed in, then the extras are ignored.

You can create an anonymous function without a name by using the following syntax

> var hi = function(name) {
  console.log("Hey " + name + "!");
}
> hi("Joe");
Hey Joe!

It is recommended to use named functions whenever possible as debugging becomes more difficult without a named context in exception chains.

Special Global Objects

Node.js has a couple of global variables that can come in handy.

  • console - The console object contains the well known log function as well as warn, time, timeEnd, and assert.
  • global - Similar to how a browser's JavaScript model has the window object which is global in scope, Node.js has the special global object.  Anything attached to it is available anywhere in your node application.
  • process - The process global variable contains information and methods about the current's environment.

Summary

It's beyond the scope of this article to get into all of the aspects of the JavaScript programming language.  For more details into the concepts I've covered, as well as others in the language, check out the JavaScript reference on w3schools.com - http://www.w3schools.com/jsref/default.asp.

Read the original blog entry...

More Stories By Joe Pruitt

Joe Pruitt is a Principal Strategic Architect at F5 Networks working with Network and Software Architects to allow them to build network intelligence into their applications.

@DevOpsSummit Stories
In his session at 20th Cloud Expo, Mike Johnston, an infrastructure engineer at Supergiant.io, discussed how to use Kubernetes to set up a SaaS infrastructure for your business. Mike Johnston is an infrastructure engineer at Supergiant.io with over 12 years of experience designing, deploying, and maintaining server and workstation infrastructure at all scales. He has experience with brick and mortar data centers as well as cloud providers like Digital Ocean, Amazon Web Services, and Rackspace. His expertise is in automating deployment, management, and problem resolution in these environments, allowing his teams to run large transactional applications with high availability and the speed the consumer demands.
SYS-CON Events announced today that DatacenterDynamics has been named “Media Sponsor” of SYS-CON's 18th International Cloud Expo, which will take place on June 7–9, 2016, at the Javits Center in New York City, NY. DatacenterDynamics is a brand of DCD Group, a global B2B media and publishing company that develops products to help senior professionals in the world's most ICT dependent organizations make risk-based infrastructure and capacity decisions.
Most DevOps journeys involve several phases of maturity. Research shows that the inflection point where organizations begin to see maximum value is when they implement tight integration deploying their code to their infrastructure. Success at this level is the last barrier to at-will deployment. Storage, for instance, is more capable than where we read and write data. In his session at @DevOpsSummit at 20th Cloud Expo, Josh Atwell, a Developer Advocate for NetApp, will discuss the role and value extensible storage infrastructure has in accelerating software development activities, improve code quality, reveal multiple deployment options through automated testing, and support continuous integration efforts. All this will be described using tools common in DevOps organizations.
Andi Mann, Chief Technology Advocate at Splunk, is an accomplished digital business executive with extensive global expertise as a strategist, technologist, innovator, marketer, and communicator. For over 30 years across five continents, he has built success with Fortune 500 corporations, vendors, governments, and as a leading research analyst and consultant.
A valuable conference experience generates new contacts, sales leads, potential strategic partners and potential investors; helps gather competitive intelligence and even provides inspiration for new products and services. Conference Guru works with conference organizers to pass great deals to great conferences, helping you discover new conferences and increase your return on investment.