1

My understand of null

0,empty = values explicitly set
Null = variable exists but it's still virgin.
Undefined = variable doesnot exists

Comments
  • 10
    0 = value is explicitly set

    null = there is no value

    undefined = you're working in a terrible language and should switch ASAP
  • 0
    @tosensei just say it (javascript).🤣. But if there will be no javascript developers then there will be no websites 😏 and no money
  • 1
    @nullcoffee there was a world of browser interaction before Javascript took the lead role.

    Vbscript could have taken off.
    actionscript could have survived.

    But, here we are.
  • 1
    @C0D4 @tosensei @nullcoffee

    https://typescriptlang.org/docs/...

    ... and if it's not bad enough, there are ways to make it worse.

    Technically, one should start with boolean logic.

    true | false

    But we have a lil unpleasant problem here - what if we don't know the value?

    Enter 3VL / 3 value logic / ternary system:

    true | false | unknown

    Note that unknown is special, easiest example is SQL where NULL = unknown ...

    Comparison against unknown - unknown.

    Note that logic operation like unknown and false is false, unknown or true is true.

    Now what some languages do for the sake of Cthulhu in my opinion is to add a 4th dimension...

    In JavaScript this is done exceptionally brain damaged.

    Null is falsy if coerced to a boolean.
    And undefined exists additionally....

    So JS is an entirely different logical concept.

    null == null - true
    null == undefined - true
    null == false - false

    But
    const value = null
    if value { "Nope" } else { "Yep" }

    (falsy if coerced to a boolean)

    TLDR: JS has a completely broken logic regarding null values and added additionally undefined to differentiate between an "uninitialized" variable vs a variable with no value (null).
  • 1
    @C0D4 well vbscript was never really a thing since MS of the time did not let the browser grow.

    Actionscript was never natively supported since it was a plugin and not universally available and flash was do abused even by “legitimate “ users that it deserved to die ;)

    And js was the thing before either vbscript or actionscript.

    And there was also jscript which was a lot more powerful than vbscript and also worked in IE.

    But js was always the one you had to use for anything but internal sites.
  • 1
    @nullcoffee there was a time before javascript, and there will be a GLORIOUS time after javascript.

    maybe blazor will set us free.

    also, another way to understanding:

    0 = your toilet paper roll is empty.

    null = you don't even _have_ a toilet paper roll.

    undefined = you're sitting on the kitchen sink. get off of there. and then get out of my kitchen, you weirdo. (great, now the tap is dripping...)
  • 1
    @tosensei web assembly is the technology powering blazor and all other languages.

    Js will most likely stay as the native lang but with webassembly more and more other languages will be useful.
  • 0
    @tosensei we should ban 'undefined'

    either you assign a value or it is null.
  • 0
    0 - value
    Null - the value is that there is nothing. Null is a value.
    Undefined - we don't know
Add Comment