JavaScript conditional ternary operator is giving error: Expected an assignment or function call and instead saw an expression when setting a variable conditional ternary operator java,conditional ternary operator c++,conditional ternary

I would like to set a param for knowing what uri to use when a certain port is called.

Here is my code:

  var portConfig = '443';
    (portConfig === '443') ? uri = 'wss://' : uri = 'http://';
    console.log(uri);
    var Ip = uri + "hereis.myurl.com";
    var port = portConfig;
    console.log(Ip);

I am getting the following error:

Expected an assignment or function call and instead saw an expression

I have even set the uri's to be inside of a function testA testB but the same error occurs. I have read up on the issue and it just seems like an erroneous error. Should I use the if statement instead -- which works fine?

Answer:1

The correct way per documentation is:

uri = (portConfig === '443') ? 'wss://' : 'http://';

It does indeed expect the assignment, not the expression.

In fact, the way you use could be eaten and parsed without the errors by the browser, since an assignment returns the assigned value. But it's not the recommended way, since the ternary operators were designed to return the value (and they do it always, even if you don't use the value afterwards), unlike if() conditions, and it's considered not wise to use it like you use if().

Answer:2

I found a guide on how to write AngularJS the right way: https://github.com/johnpapa/angular-styleguide#factories In Laravel, I created my POST route /api/addnew and now I need to pass params from ...

I found a guide on how to write AngularJS the right way: https://github.com/johnpapa/angular-styleguide#factories In Laravel, I created my POST route /api/addnew and now I need to pass params from ...

  1. database record with
  2. record in database definition
  3. database record and field
  4. record in database management system
  5. record in database meaning
  6. record in database example
  7. record in database table
  8. database record in hindi
  9. database record on excel
  10. record in database file

I'm trying to recreate some JQuery tutorials that I've seen, by myself, but I'm stuck right now. I'm creating an object that starts at a position and ends at another position. The figure changes, but ...

I'm trying to recreate some JQuery tutorials that I've seen, by myself, but I'm stuck right now. I'm creating an object that starts at a position and ends at another position. The figure changes, but ...

  1. changing color when knitting
  2. changing color when crocheting
  3. changing color when knitting in the round
  4. change color when hover css
  5. change color when click css
  6. change color when hover
  7. change color when click button
  8. change color when checkbox
  9. change color when
  10. changing color on photoshop
  11. changing color on car
  12. changing color on skin
  13. change color on ps4 controller
  14. change color on picture
  15. change color on image
  16. change color on outlook
  17. change color on iphone
  18. change color on messenger
  19. change color on photo
  20. change color on google calendar

I have a JavaScript-array with objects filled in and want to remove every object with no data. It might look like this: var myArray = [ {id: "28b", text:"Phill"}, {id: "12c", text:"...

I have a JavaScript-array with objects filled in and want to remove every object with no data. It might look like this: var myArray = [ {id: "28b", text:"Phill"}, {id: "12c", text:"...

  1. remove empty objects from json
  2. remove empty objects from array javascript
  3. remove empty objects from array lodash
  4. remove empty objects from json java
  5. remove empty objects from object javascript
  6. remove empty objects lodash
  7. remove empty objects
  8. remove empty objects from array php
  9. remove empty objects from array java
  10. remove empty objects from list java
  11. remove empty objects from json c#
  12. remove empty objects from list c#
  13. remove empty objects from arraylist
  14. remove empty object mongodb
  15. remove empty objects python
  16. js remove empty objects from array
  17. jackson remove empty objects
  18. javascript remove empty objects from json
  19. powershell remove empty objects from array
  20. python remove empty objects from list

In local storage I have an object named favourites and it contains this.. "{ "id3333":{ "URL":"somewhere.comm/page1/", "TITLE":"Page 1 Title", }, "id4444":{ "URL":"...

In local storage I have an object named favourites and it contains this.. "{ "id3333":{ "URL":"somewhere.comm/page1/", "TITLE":"Page 1 Title", }, "id4444":{ "URL":"...

  1. c++ delete object within itself
  2. javascript delete key within object