JS的基础语法(Math和String)

js  ECMA 标准化
核心语言定义:Math、String、Boolean、Number、Date、Array、Object、Funvtion、ExpReg 

Math 

<script>
    console.log(Math.PI);
    console.log(Math.round(6.8)); //五入
    console.log(Math.round(6.2)); //四舍
    console.log(Math.pow(3,5));   //x的y次幂
    console.log(Math.ceil(6.8)); //向上取整
    console.log(Math.abs(-5));  //绝对值
    console.log(Math.floor(2.7));  //向下取整
    console.log(Math.ceil(Math.random()*(10-1)+1));
</script>

string

<script>
//  1.1字符串的创建
    var str1 = new String('hello world');
    var str2 = 'hello javascript';
    console.log(str1,str2);
//   2.1 length属性
    console.log(str1.length,str2.length);
//    3.1  charAt方法
    document.write("<p>查找指定字符"+str1.charAt(str1.length-1)+"</p>");
//    3.2  concat方法
    var str3 = str2.concat(' we love');
    console.log(str3);
//    4.1截取字符串
    console.log(str1.slice(2,8));
//    5.1字符串第一次出现的位置
    console.log(str1.indexOf("l"));   /*如果没有找到指定字符,则会返回-1*/
//    6.查找字符串
    console.log(str1.replace("world","JavaScript"))
//    7.查找字符
console.log(str1.search("world"));
//    8.分割字符串    /*important*/
    console.log(str1.split("l"));
//    9.清除字符串两边的空格
    console.log(str1.trim());
</script>

 

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值