zoukankan      html  css  js  c++  java
  • js四则运算符

    只有当加法运算时,其中一方是字符串类型,就会把另一个也转为字符串类型。其他运算只要其中一方是数字,那么另一方就转为数字。并且加法运算会触发三种类型转换:将值转换为原始值,转换为数字,转换为字符串。

    <template>
      <section class="p-10">
        <el-button type="danger" @click="get()">点击</el-button>
      </section>
    </template>
    <script>
      export default {
        data() {
          return {
          }
        },
        methods: {
          get() {
            console.log(10 + '1');
            console.log(10 - '1');
            console.log(10 * '1');
            console.log(10 / '1');
          }
        }
      };
    </script>

    对于加号需要注意这个表达式 'a' + + 'b'

    <template>
      <section class="p-10">
        <el-button type="danger" @click="get()">点击</el-button>
      </section>
    </template>
    <script>
      export default {
        data() {
          return {
          }
        },
        methods: {
          get() {
            console.log(+ '1');
            console.log(- '1');
            console.log(+ 'b');
            console.log(- 'b');
            console.log(1 + + '1');
            console.log('1' + + '1');
            console.log('1' - + '1');
            console.log('1' * + '1');
            console.log('1' / + '1');
            console.log('1' + + 'b');
          }
        }
      };
    </script>

    嗯,就酱~

  • 相关阅读:
    淘宝Banner 轮播图
    JavaScript move简易版运动框架封装
    javaScript 导航栏
    JS 运动框架完整版
    Js 数组操作
    JS 动画轮播效果
    JavaScritpt 字符串操作
    Java AOP切面编程方式
    时间版 运动框架
    Nmon的安装及使用
  • 原文地址:https://www.cnblogs.com/jin-zhe/p/10070095.html
Copyright © 2011-2022 走看看