Tag Archives: JavaScript

Use of !! in JavaScript


Want to find out if something is false if it is a string, number, obj etc….

var x = “No”
typeof x
// string

var xBools = !!x;
//true – because variable x has a string of No, could be a string of false as well. A string is an object and that object has alpha characters
typeof xBools
// boolean

var emptyString = “”;
typeof emptyString 
// string

var emptyStringBools = !!emptyString;
//false – because the string is empty
typeof emptyStringBools 
// Boolean

var nulls = null;
typeof nulls
// object

var nullsBools = !!nulls;
typeof nullsBools
// boolean

var under;
typeof under
// undefined

var underBools = !!under;
typeof underBools
// boolean

Check to see if a variable has a value and if that value is usable.

How to : Add custom validation to a Mongoose Model

I need to add a custom validation to my mongoose model before I save to my Mongo Database.

Answer –

  • Custom validation is declared by passing a validation function.


  • Note* Custom validation – method signature = validate(obj, [errorMsg])

var phoneValidator = [
   return /d{3}-d{3}-d{4}/.test(v); 
 "Please provide a valid phone number"

var customerSchema = new Schema(
   phone : 
     type: String, 
     validate: phoneValidator 

var Customer = mongoose.model('customer', customerSchema);  

Getting Started with Polymer

cloud 9 idegithub
Google Polymer

In this tutorial we will get familiar with Google Polymer. Learn the basics on importing HTML files, and use the custom polymer tags. Also, touch a little on implementing the paper style polymer elements and use Bower to get it all rolling within the Cloud 9 web based IDE.

Note * Cloud 9 IDE and gitHub are free accounts.
As a UI developer, I highly recommend creating an account for gitHub and keeping it up to date with what you have learned and special projects.

Continue reading

In depth JavaScript : Apply / Call

Why use Apply or Call?

Call takes the value to be used as the “this” object as the first object in the parameter list. The rest of the parameters will come after the first object and separated by commas.

callFunction.call(thisObjectPassedIn, param1, param2)

Apply is just like call but the second parameter is an array of parameters.

applyFunction.apply(thisObjectPassedIn, [param1, param2])

In depth JavaScript : Callbacks

JavaScript – Object based language

Functions are OBJECTS

var myFunction = function(){

function doFunction(myFunction){
  //do something

Things to understand about functions

  • functions can be stored as a variable
  • functions take parameters that can be variables
  • can be created by functions
  • can be returned from functions

Continue reading