Automatic Conversion between Types
<HTML>
<HEAD>
<TITLE>Implicit conversion between types</TITLE>
<SCRIPT LANGUAGE="JavaScript">
<!--
s1="test"
s2="1122.34"
i=123
r=.123
lt=true
lf=false
n=null
// -->
</SCRIPT>
</HEAD>
<BODY>
<H1>Implicit conversion between types</H1>
<TABLE>
<SCRIPT LANGUAGE="JavaScript">
<!--
document.write("<TR>")
document.write("<TH>row + column</TH>")
document.write("<TH>string \"12.34\"</TH>")
document.write("<TH>integer 123</TH>")
document.write("<TH>float .123</TH>")
document.write("<TH>logical true</TH>")
document.write("<TH>logical false</TH>")
document.write("<TH>null</TH>")
document.write("</TR>")
// First operand is a string
document.write("<TR>")
document.write("<TH>string \"test\"</TH>")
document.write("<TD>")
document.write(s1+s2)
document.write("</TD><TD>")
document.write(s1+i)
document.write("</TD><TD>")
document.write(s1+r)
document.write("</TD><TD>")
document.write(s1+lt)
document.write("</TD><TD>")
document.write(s1+lf)
document.write("</TD><TD>")
document.write(s1+n)
document.write("</TD>")
document.write("</TR>")
// First operand is an integer
document.write("<TR>")
document.write("<TH>integer 123</TH>")
document.write("<TD>")
document.write(i+s2)
document.write("</TD><TD>")
document.write(i+i)
document.write("</TD><TD>")
document.write(i+r)
document.write("</TD><TD>")
document.write(i+lt)
document.write("</TD><TD>")
document.write(i+lf)
document.write("</TD><TD>")
document.write(i+n)
document.write("</TD>")
document.write("</TR>")
// First operand is a float
document.write("<TR>")
document.write("<TH>float .123</TH>")
document.write("<TD>")
document.write(r+s2)
document.write("</TD><TD>")
document.write(r+i)
document.write("</TD><TD>")
document.write(r+r)
document.write("</TD><TD>")
document.write(r+lt)
document.write("</TD><TD>")
document.write(r+lf)
document.write("</TD><TD>")
document.write(r+n)
document.write("</TD>")
document.write("</TR>")
// First operand is a logical true
document.write("<TR>")
document.write("<TH>logical true</TH>")
document.write("<TD>")
document.write(lt+s2)
document.write("</TD><TD>")
document.write(lt+i)
document.write("</TD><TD>")
document.write(lt+r)
document.write("</TD><TD>")
document.write(lt+lt)
document.write("</TD><TD>")
document.write(lt+lf)
document.write("</TD><TD>")
document.write(lt+n)
document.write("</TD>")
document.write("</TR>")
// First operand is a logical false
document.write("<TR>")
document.write("<TH>logical false</TH>")
document.write("<TD>")
document.write(lf+s2)
document.write("</TD><TD>")
document.write(lf+i)
document.write("</TD><TD>")
document.write(lf+r)
document.write("</TD><TD>")
document.write(lf+lt)
document.write("</TD><TD>")
document.write(lf+lf)
document.write("</TD><TD>")
document.write(lf+n)
document.write("</TD>")
document.write("</TR>")
// First operand is null
document.write("<TR>")
document.write("<TH>null</TH>")
document.write("<TD>")
document.write(n+s2)
document.write("</TD><TD>")
document.write(n+i)
document.write("</TD><TD>")
document.write(n+r)
document.write("</TD><TD>")
document.write(n+lt)
document.write("</TD><TD>")
document.write(n+lf)
document.write("</TD><TD>")
document.write(n+n)
document.write("</TD>")
document.write("</TR>")
// -->
</SCRIPT>
</TABLE>
</BODY>
</HTML>
Related examples in the same category