Saturday, May 12, 2018

JavaScript and Camel Case

JavaScript and Camel Case


Historically, programmers have used different ways of joining multiple words into one variable name:
Hyphens:
first-name, last-name, master-card, inter-city.
Hyphens are not allowed in JavaScript. They are reserved for subtractions.

兩個等於(==)會對被判別的變數做轉換型別的動作(coercion又稱為implicit type conversion)。這就是爲什麽有時候不懂一個語言特性會覺得怪怪的。舉例來說


左邊是int type右邊是string type,但是因為兩個等於會把 string 轉型為int,所以實際比對是1 = 1所以是true

如果是三個等於(===),那麼就不會有轉換型別的問題,因此1 === "1" //false就是false。

Null

In JavaScript null is "nothing". It is supposed to be something to be something that does not exist.
unfortunately, in JavaScript, the data type of null is an object.
You can consider it a bug in JavaScript that typeof null is an object. It should be null.

Function Invocation
The code inside the function will execute when "something" invoke (calls) the function:
- when an event occur (when a user clicks a button)
- When it is invoked (called) from JavaScript code
- Automatically (self invoked).


The () Operator Invoke the Function

Using the example above, toCelsius refers to the function object, and toCelsius() refers
to the function result.
Accessign a function without () will return the function definition instead of the function result.

Functions Used as Variable Values

Functions can be used the same way as you use variables, in all types of formulas, assignments, and calculations.

Example

Instead of using a variable to store the return value of a function:
var x = toCelsius(77);
var text = "The temperature is " + x + " Celsius";
You can use the function directly, as a variable value:
var text = "The temperature is " + toCelsius(77) + " Celsius";


No comments:

Post a Comment