Home PC Games Linux Windows Database Network Programming Server Mobile  
  Home \ Programming \ JavaScript basic types and type conversion     - The wrong in Linux: too many open files (Linux)

- MySQL related statements (CRUD) (SQLyog software) (Database)

- Some common Linux commands Study Notes (Linux)

- Kickstart automated installation and deployment RHEL 7.0 (Linux)

- Linux_Logo - output color ANSI Linux distributions logo command-line tool (Linux)

- KVM add virtual disks (Linux)

- C # using the HttpClient Note: Preheat the long connection (Programming)

- MySQL stored procedures and triggers (Database)

- AngularJS - Custom instructions (Programming)

- Teach you the Ubuntu Server enabled SSH multifactor authentication (Server)

- Use rfkill soft-switching and Bluetooth wireless capabilities in Linux (Linux)

- Easy to get hidden administrator account (Linux)

- PostgreSQL 9.3.5 database installation under Ubuntu Server 14.04 (Database)

- Configuring s3c-linux- appears Unable to find the QT3 installation (Linux)

- Vi (Vim) keyboard map and its basic commands (Linux)

- Chromium Install Flash Official Guide (Linux)

- To share Linux script automatically change passwords (Linux)

- ld.so.conf.d profile (Linux)

- Nginx caching using the official guide (Server)

- CKEditor + SWFUpload achieve a more powerful editor (Linux)

  JavaScript basic types and type conversion
  Add Date : 2017-01-08      
  Each language has its own basic types, JavaScript is no exception. In JavaScript there are five basic types are number, string, boolean, null, undefined. The other does not belong to the five basic types of objects are sometimes also h is a null object.

First, the basic type of presentation

It can be determined by what type of typeof.

number includes basic digital, Infinity, unInfinity, NaN. Wherein NaN rather special, can not be done in one operation, when do you get a result NaN operation, for example, 1 * 'abc'.

Almost all of the string type of language has, but the implementation is different.

boolean is very common base type, only two values true and false.

null is actually empty

undefined undefined refers

Second, the type conversion

Any language can type conversion. Special thing javascript her back to do some automatic type conversions, benefits of doing so is that developers do not have to do some type of forced conversion, but this feature is also regarded as one of javascript criticized, many people think that this feature can cause some unexpected mistake. Of course, I think once you have a good type conversion features and details, you can while avoiding disadvantages.

Some say in the type conversion error-prone place.

In making the + operator must pay attention because in javascript, + either a digital adder, can also be a string concatenation. When one of the two operands is another numeric string will be converted to a string, then a string concatenation, for example '12 + 1 'and' 1 '+ 12 is obtained string' 112 ' . So if you want to do digital addition, we must ensure that both operands are numbers, you can use Number mandatory conversion, such as 1 + Number ('12 '). Of course, you can use some simple conversions such as 1 + 1 * '12 '. However, these two approaches are not recommended, because semantics is not clear, who will read the code caused confusion or misunderstanding.

Any variable can be converted to a Boolean value, not true is false. Common empty string '', undefined, null, NaN, 0 can be converted to false. Others are all true.

When we define the variable, often we do var a = a || 10. We want to do is, if a is defined using a value is not defined but often ignored assigned to 10. If a value of zero. Therefore, this definition method must be used with caution.

In javascript to do other more when there are two approaches, one is another == === corresponding unequal comparisons! = And! ==. === Strict equality is called. The difference is that == === do not type conversions, such as 1 == '1', 1 == true will return true, and 1 === '1', 1 === true then It returns false. So do the other more when you also must be careful.

Third, the summary

As a weakly typed language, javascript type conversion on the one hand to developers to bring a lot of convenience and sought after by the people, on the other hand also have some inexplicable errors people who were abusive. Actually, I think any language is not perfect, but we can do is really master these characteristics may produce errors, while avoiding disadvantages is king.
- jQuery plugin dynamic label generation (Linux)
- Linux ldconfig command (Linux)
- C ++ you can become a new scripting language (Programming)
- Some problems and countermeasures Linux system calls exist (Linux)
- Shell script to crawl through AWR SQL Report Problems (Database)
- Static member variable modified (Programming)
- Cobbler remotely install CentOS system (Linux)
- To restore the last time applications running when Ubuntu user log in again (Linux)
- AngularJS - Custom instructions (Programming)
- Zend Studio PHP syntax color scheme to export (Linux)
- Daemon under Linux (Linux)
- C ++, overloading, cover, hide (Programming)
- CentOS card fails to start at boot progress bar certmonger solve (Linux)
- RHEL5 multipath configuration (Linux)
- Graphical interface for the CentOS 6.4 installed and connected by remote VNC (Linux)
- KVM installation under CentOS 5.5 (Linux)
- ORA-600 [kcbz_check_objd_typ] Error Handling (Database)
- CentOS 7.0 Close firewall is enabled by default iptables firewall (Linux)
- Introduction to Linux system process monitoring tools (Linux)
- Create a custom pixel format based on an existing image data BufferedImage (Programming)
  CopyRight 2002-2022 newfreesoft.com, All Rights Reserved.