ComputersProgramming

JavaScript: typeof - need or new features

Previously there were data of a particular type and it was of interest to process them in order to obtain a result. The domination of "atypical ideas in the field of description" came unexpectedly, but naturally. The preliminary declaration of a variable has ceased to be mandatory, and the indication of its type in general has lost all meaning, at least before the operation in which it takes part.

The programmer untied his hands: it is not at all necessary to declare something at the beginning. Often, only by the time of use will there be certainty, what to take, what to do and how. As for the types, they by themselves "became values", that is, they became data, which also depends on something!

It's still there or not, so what if

A very simple description of the variable "aaa" and the available algorithm for its processing:

aaa ; Var aaa ;

( aaa ) { If ( aaa ) {
= 'I am!' Res = 'I am!' ; // I AM!
{ } Else {
= 'me no...' ; Res = 'me no ...' ; // I do not have
}

Will give an obvious result: "I do not." Here the value of the JavaScript function typeof = undefined. Just describe the variable - "nothing at all" does not mean. Of course, when aaa = 1, we get: "I AM!", But if aaa = 0, it will be like in the first case: "I'm not ...". Wonderful logic, another mathematician, and also a common citizen, could not even think that zero meaning has a completely different meaning than the real one. Only modern (atypical) programming is capable of such bold ideas!

The JavaScript typeof, like the more intelligent expression if (aaa) {... x ...} else {... y ...}, has excellent consumer qualities and is very user-friendly.

On the features of Cyrillic and Latin

A professional programmer will always prefer English characters to Russian, sincerely thanks to that stage of programming development, when cybernetics was not recognized in some areas, but in other territories computer science confidently went up the hill. The programming languages began to multiply and develop, taking as a basis the syntax of the 26 letters of the English alphabet and a set of other generally accepted symbols.

The simplest and most natural was the machine code, it was beautiful, perfect, but specific to each architecture, and in high-level languages the idea of portability between architectures immediately became relevant. This essentially contradicts the current moment: the grounds for the analogue JavaScript typeof = undefined | String | Number | Boolean | Object | Function then simply was not. All languages were strictly formal, had a strict syntax and did not allow uncertainty.

Types, variables and their use

The moment is very important. Typification and description of variables is the most important component of the program, the programmer can not write the working algorithm until he puts the actual data variety into a strict formal picture of variables, arrays, objects and functions.

JavaScript carries with it all the functional power accumulated over the decades, all its designs perfectly reflect modern ideas about the syntax and expedient rules of putting semantics into it.

The question is, when should this be done, when exactly is it necessary to determine the type text, JavaScript typeof function. Actually clean options of type text a little: a character, a string and a number. However, the object can play the role of the text, and even an array with the array.join () construct that connects all its elements into a single text, that is, in one line.

Banal statement: everything around is type text, and the JavaScript typeof function must at the right time perform the required type definition. It's true, but in practice everything turns out differently. JavaScript typeof object will return the same value in all three cases:

aaa = {}; Var aaa = {};
= typeof ( aaa ); Res = typeof ( aaa );
+= '/' + typeof window . Res + = '/' + typeof window . ; Document ;
+= '/' + typeof ( document . forms [ 0 ]); Res + = '/' + typeof ( document . Forms [ 0 ]);

Result: object / object / object

The use of the function can be in the format typeof (aaa) and format typeof aaa - this is not essential, but in all cases the answer is given, but it does not mean anything at all!

Uncertainty passes into certainty

Programming is characterized by a special dynamics: it so rapidly flies forward that the scale of motion is continuously expanding. The account goes for months, weeks or days, and sometimes even hours. In specific problems, the dynamics of the solution algorithm formation is so fast and demanding to continuity that the programmer's exit from the working state can discard the decision for a day, a week and a longer time.

The natural solution of the JavaScript typeof and the practice of object-oriented programming, which in this syntax is somewhat different from the existing in adjacent modern languages, transfers the center of gravity to the object. A very characteristic moment: language becomes a construction containing semantics, and not a set of syntactic norms.

Simple data types do not need to define their type, rather the use of JavaScript typeof is enough. If necessary, the runtime itself takes care of the proper transformations, but with respect to JavaScript objects typeof gives the most reasonable answer: it is an object and the problem of its type is its care! Such logic for the classical view of programming is difficult to perceive, but this is the real position of the right things.

Caring for an object is to define your type, manifest your properties and perform your methods. Programming polished its syntax and with every moment of time transfers the center of gravity from the syntax to the semantics formed by the programmer: the system of its objects that perform the solution of the task.

Similar articles

 

 

 

 

Trending Now

 

 

 

 

Newest

Copyright © 2018 en.unansea.com. Theme powered by WordPress.