Friday 15 August 2014

javascript - General constructor for all JS types -


If I'm trying to declare a variable and I need to provide a default case because it makes me key I will not, without any price, thought that I can make the same basic value for all empty variables, but it still should be of the type that I want when I really believe in it.

  var x = ""; Var y = 0; Var z = null;   

I know that JS is very good about knowing (except those crazy situations between strings and numbers), but in writing over null Will be enabled by all types, and then that variable will be that type?

So if we have var x = ""; Then the X string is already obvious, if I did var x = "something" , then it would still be a string, or if I had the value of var x = 12 < / Code>, it will change the type and value.

What type is it assigned to null ?

So what is your suggestion for placeholder value for a variable that only needs to be made?

faucet = item;

Undefined = any type specified

In Javascript, everything is an object of some form or another, unless it has been associated with any data, in which case This is undefined .

Something like this:

  var default = {beats: "", number of beats: 0, representation: undefined};   

Then in your code you can ask that there is any data by representation index:

  if ( Typeof defaults ['representation]] === "undefined" {// representation has not yet been defined}    

No comments:

Post a Comment