-
Notifications
You must be signed in to change notification settings - Fork 0
Home
This repository is part of a larger project!
In Javascript the operator "+" allows not only to sum "number" values but also to concatenate two or more strings.
The operator has another interesting feature which permits turning a string into a "number".
With the help of an example this will be now explained:
1. A text box in HTML is generated as follows
<input type="text" id="txt_one">
2. The value from the text box is fetched and converted as follows
<script>
var myValue = +document.getElementById("txt_one").value;
</script>
There is an issue here which is the lack of knowledge from my side, how the converting property is working! If you at any rate know some explanation or better a valid source, please post it under the section Issues in this github project!Thank you very much!
🥇 The ISSUE has been solved by dotnetCarpenter
Starting "index.html" in a web browser should show a content as seen below.
There are three sections in the picture.
1. Section "Addition" allows to calculate the sum of two numbers.
2. Section "Concatenating strings" allows to concatenate two strings to one.
3. Section "Pitfall examples" shows some examples which can produce results that should be avoided.
The results could be displayed as shown in the picture below.
The colored areas are just for a better readability in the wiki and are not part of the content. To use the project just download the files and execute "index.html". Note that all files should be placed in the same folder so that the functionality of the code is guaranteed.
This knowledge was gained:
Effective JavaScript "68 Specific Ways to Harness the Power of JavaScript" by David Herman
Solved Issues:
Converting from string to number with the operator + by dotnetCarpenter