This article gives an introduction into variables in Javascript and how related functions like declaration, initialization and splitting work. With a simple example we show you how to use the variables in the configurator backend. If you are searching for a certain term or function, use the search function on your key board (command-F).

  • var: define a variable

  • = initialize: assign a value to the variable (use a equal sign (=) to do so)

  • == compare variables

  • === compare data types of variables 

  • != unequal

  • and / or operators : "and" is expressed by AND or $$ ; "or is expressed by OR or || (Alt => 7)

  • declare: assign a datatype to your variable (string or number)

  • integer: expressed by S

  • delimiter: expressed by _ 

  • replace: with the function replace you can replace values and characters in a term . An example: javascript usually calculates in the english spelling of numbers, meaning with dots instead of commas in values with decimal points. 2,5 is expressed by 2.5. Later in the frontend you want the number to be expressed as 2,5. Thus you have to replace the dot by a comma. The corresponding javascript is replace (".",",")   

  • replace: with the function replace you can replace values and characters in a term. An example: javascript usually calculates in the english spelling of numbers, meaning with dots instead of commas in values with decimal points. 2,5 is expressed by 2.5. Later in the frontend, you want the number to be expressed as 2,5. Thus you have to replace the dot by a comma. The corresponding javascript function is replace (".", ","). 

  • if...else: in Javascript an if-else-relationship is expressed by ?...: or by if{...} {...}else. This function means that if a certain condition is true, then a certain step should be carried out, otherwise something else is carried out or nothing happens 

  • toString: transform a number into a string aus einer Zahl eine Zeichenkette machen 

  • typeof: With typeof "x" Javascript checks which data type a certain value has, meaning whether it is  X must be replaced here by the specific value that has to be examined.  Mit typeof "Wert" gibt Javascript aus, aus welchem Typ der Wert besteht, also ob es sich um eine Zahl oder eine Zeichenkette handelt. 

  • toFixed: determines the number of decimal points. If you want a number to have zwei decimal points, you use the command toFixed(2)

  • parsInt: a string is transformed in a number 

  • split?

  • Connection with constants? 

  • math.floor / math.round: term to round up and round off decimal values to full numbers

  • if...<0 the if-functioning in Javascript can express some relationships between values. if...<0 for example expresses: If the value is smaller than zero, then... . In the same way you can use if...>0 and if ...=0.  

War diese Antwort hilfreich für dich?