1

Topic: [JS] undefined, null, another?

We read specification ECMAScript: http://es5.javascript.ru/x4.html#x4.3.9 4.3.9 Indefinite value (undefined value) # (T) - the primitive value used in the event that a variable has not been appropriated values. 4.3.11 Empty value (null value) # (T) - primitive value in which  there is a value of object. We declare object and for clearness it is registered its fields with empty values: var someObj = {integerField: _, stringField: _, objectField: _}; you so write? If yes, that use in quality _ - null or undefined? Or another: 0, "", {}?

2

Re: [JS] undefined, null, another?

Hello, yenik, you wrote: Y> we Declare object and for clearness it is registered its fields with empty values: Y> Y> var someObj = {Y> integerField: _, Y> stringField: _, Y> objectField: _ Y>}; Y> If to write so var someObj1 = {integerField: undefined, stringField: undefined, objectField: undefined,}; var someObj2 = {}; that someObj1.integerField === undefined, and also someObj2.integerField === undefined. I.e. with undefined initialization that is property that it is not present - indistinguishably (almost). Such behavior is necessary to you? Same integerField: null means property is, but value indefinitely. I.e. all depends on that that is necessary to you.

3

Re: [JS] undefined, null, another?

CS> I.e. with undefined initialization that is property that it is not present - indistinguishably (almost). CS> such behavior is necessary to You? CS> Same CS> CS> integerField: null CS> CS> means property is, but value indefinitely. CS> I.e. all depends on that that is necessary to you. Yes to me, by and large, all the same. That so empty value that . integerField is in this case id which should be more zero. Then check looks so: if (someObj.integerField) {...} There is no practical difference between null, undefined and 0. At me the question is faster from the point of view of feng shui. Simply it would be desirable definiteness. Well it is fine, Number is a little specific example (m. It is reasonable to deliver 0). More interesting about String and Object. I have a sensation that is better null: 4.3.11 Empty value (null value) # (T) - primitive value in which  there is a value of object. And the same concerns the values returned by function because reset undefined is too similar on missing in function return - whether function is written with an error, whether used not for the designated purpose. However some colleagues consider differently. And them unexpectedly supports TypeScript Coding Guidelines. null and undefined Use undefined, do not use null. And TS-sheep really so write. https://github.com/Microsoft/TypeScript … erences.ts result.push ({definition: undefined, references: [{fileName: sourceFile.fileName, textSpan: createTextSpan (position, searchText.length), isWriteAccess: false, isDefinition: false}]}); In specification TS anything distinct how to use null and undefined it is not written. Yes, I in a subject wrote JS, instead of TS, however I do not think that TS absolutely .

4

Re: [JS] undefined, null, another?

Hello, yenik, you wrote: Y> Yes to me, by and large, all the same. That so empty value that . Y> integerField is in this case id which should be more zero. Then check looks so: if (someObj.integerField) {...} Y> There is no practical difference between null, undefined and 0. Y> At me the question is faster from the point of view of feng shui. Simply it would be desirable definiteness. Y> well it is fine, Number is a little specific example (m. It is reasonable to deliver 0). Y> it is more interesting about String and Object. I have a sensation that is better null: There is one interesting thing if (typeof value == "object") For null the true gives. The difference is. Between value and  is installed. null this value is installed.

5

Re: [JS] undefined, null, another?

Hello, Serginio1, you wrote: S> Hello, yenik, you wrote: Y>> Yes to me, by and large, all the same. That so empty value that . Y>> integerField is in this case id which should be more zero. Then check looks so: if (someObj.integerField) {...} Y>> There is no practical difference between null, undefined and 0. Y>> At me the question is faster from the point of view of feng shui. Simply it would be desirable definiteness. Y>> well it is fine, Number is a little specific example (m. It is reasonable to deliver 0). Y>> it is more interesting about String and Object. I have a sensation that is better null: S> There is one interesting thing S> S> if (typeof value == "object") S> S> For null the true gives. S> the difference is. Between value and  is installed. S> null this value is installed. I know, in what a difference between null and undefined. But in practice this difference is almost always insignificant: if (someObj.integerField) {...} console && console.log && console.log (' debug string ');

6

Re: [JS] undefined, null, another?

Hello, yenik, you wrote: S>> There is one interesting thing S>> S>> if (typeof value == "object") S>> S>> For null the true gives. S>> the difference is. Between value and  is installed. S>> null this value is installed. Y> I know, in what a difference between null and undefined. But in practice this difference is almost always insignificant: Y> if (someObj.integerField) {...} Y> console && console.log && console.log (' debug string '); to Whom as. I for example for transmission of the termination of the iterator from.Net transfer undefined CEF, ES6, Angular 2, TypeScript usage of classes.Net Core. Creation  GUI for.Net by means of CEF It faster and more conveniently. It can be applied by analogy with Dictionary by search instead of TryGetValue .

7

Re: [JS] undefined, null, another?

S> to Whom as. I for example for transmission of the termination of the iterator from.Net transfer undefined It depends. In different languages and libraries search of elements differently implement. It is possible and so. I do not say that undefined it is impossible to use. TypeScript not fools write tea, and at them the convention - undefined. But whether pertinently to follow this convention in JS? What standard/recommended practice in JS? document.getElementById ("q") null - did not find [1,2,3].find (e => e === 2) 2 - found [1,2,3].find (e => e === 4) undefined - did not find [1,2,3, undefined].find (e => e === undefined) undefined - found!

8

Re: [JS] undefined, null, another?

Hello, yenik, you wrote: S>> to Whom as. I for example for transmission of the termination of the iterator from.Net transfer undefined Y> It depends. In different languages and libraries search of elements differently implement. It is possible and so. I do not say that undefined it is impossible to use. TypeScript not fools write tea, and at them the convention - undefined. But whether pertinently to follow this convention in JS? What standard/recommended practice in JS? Y> document.getElementById ("q") Y> null - did not find Y> [1,2,3].find (e => e === 2) Y> 2 - found Y> [1,2,3].find (e => e === 4) Y> undefined - did not find Y> [1,2,3, undefined].find (e => e === undefined) Y> undefined - found! In JS that that I saw it in the core undefined Analogue undefined it most likely BDNull and there comparing on Null always Null