Skip to content

comparing strings (difference between == and ===) #621

@trusktr

Description

@trusktr

I'm trying to write some code using assert:

	assert(
		s.toString() === '{W: 20.0, H: 30.0}',
		'toString should be "{W: 20.0, H: 30.0}". Got: "' + s.toString() + '"'
	)

and the assert fails with output showing that the strings are equal (despite failing):

toString should be "{W: 20.0, H: 30.0}". Got: "{W: 20.0, H: 30.0}"

As far as I can tell, the strings look identical (I copy and paste them into JS console, and === shows true).

But if I try to use ==, then I get a runtime error:

output from my abort function:

msg: 0 <-- assert() call in rt/pure.ts has no message
 file: ~lib/rt/pure.ts
 line: 115
 col: 13

Error in console:

Uncaught (in promise) RuntimeError: unreachable
    at wasm-function[19]:41
    at wasm-function[20]:14
    at wasm-function[41]:365
    at wrap (http://127.0.0.1:8080/js/as-loader.js:250:12)
    at runGlas (http://127.0.0.1:8080/ts/index.js:68:9)

Screen Shot 2019-05-29 at 8 35 02 AM

How should I compare the strings?

Metadata

Metadata

Assignees

No one assigned

    Labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions