javascript type conversions [subjective]

asked 2018-12-25 18:06:51 +0300

Tanghus gravatar image

updated 2018-12-27 15:52:12 +0300

DISCLAIMER: I may be freaking blind! (I probably am...) ;)

I am having some problems with type conversions, where a number turns into a boolean:

The model:

ListModel {
    id: alignmentModel
    ListElement { align: qsTr("Left"); value: Dock.Left } // 0
    ListElement { align: qsTr("Right"); value: Dock.Right } // 2
}

Get the 2nd value:

typeof alignmentModel.get(1).value

number

Store it in a variable:

var tmp = alignmentModel.get(1).value

Now watch:

typeof tmp

boolean

WTF?

edit retag flag offensive reopen delete

The question has been closed for the following reason "too subjective and argumentative" by Tanghus
close date 2018-12-27 15:52:51.589387

Comments

see.notjing. did.you trace out.the value itself ?

pawel ( 2018-12-25 19:27:19 +0300 )edit

@pawel I simply used console.log and console.assert.

Tanghus ( 2018-12-25 22:38:26 +0300 )edit

and the value was 2?

i did try out your sample in node and result was always: number

pawel ( 2018-12-26 09:42:52 +0300 )edit

and the value was 2?

The value was 2, but was converted to true

i did try out your sample

And you tried it on the phone (or emulator)?

Tanghus ( 2018-12-26 15:22:49 +0300 )edit

nope, i was doing sonething in node.js so did try it there on my laptop

i will try it tomorrow in qtcreator

pawel ( 2018-12-26 18:44:18 +0300 )edit